API reference

Contents

API reference#

qse#

Quantum Simulation Environment.

This package is adapted from Atomic Simulation Environment (ASE).

class qse.Qbit(label='X', state=(1, 0), position=(0, 0, 0), qbits=None, index=None)[source]#

Class for representing a single qbit.

Parameters:
  • label (str or int) – Can be a str or an int label.

  • state (list or tuple or np.ndarray) – Quantum state of the qubit

  • position (list or np.ndarray) – Sequence of 3 floats qubit position.

  • qbits (qse.Qbits) – The Qbits object that the Qbit is attached to. Defaults to None.

  • index (int) – The associated index of the Qbit in the Qbits object. Defaults to None.

Notes

You can create a qbit object with

>>> q = qse.Qbit()
cut_reference_to_qbits()[source]#

Cut reference to qbits object.

delete(name)[source]#

Delete name attribute.

get(name)[source]#

Get name attribute, return default if not explicitly set.

get_raw(name)[source]#

Get name attribute, return None if not explicitly set.

property label#

Integer label asigned to qubit

property position#

XYZ-coordinates

set(name, value)[source]#

Set name attribute to value.

property state#

Quantum state of qubit as 2-column

property x#

X-coordinate

property y#

Y-coordinate

property z#

Z-coordinate

class qse.Qbits(labels=None, states=None, positions=None, scaled_positions=None, cell=None, pbc=None, celldisp=None, constraint=None, calculator=None, info=None)[source]#

The Qbits object can represent an isolated molecule, or a periodically repeated structure. It has a unit cell and there may be periodic boundary conditions along any of the three unit cell axes. Information about the qbits (qubit state and position) is stored in ndarrays.

Parameters:
  • labels (list of str) – A list of strings corresponding to a label for each qubit.

  • states (list of 2-length arrays.) – State of each qubit.

  • positions (list of xyz-positions) – Qubit positions. Anything that can be converted to an ndarray of shape (n, 3) will do: [(x1,y1,z1), (x2,y2,z2), …].

  • scaled_positions (list of scaled-positions) – Like positions, but given in units of the unit cell. Can not be set at the same time as positions.

  • cell (3x3 matrix or length 3 or 6 vector) – Unit cell vectors. Can also be given as just three numbers for orthorhombic cells, or 6 numbers, where first three are lengths of unit cell vectors, and the other three are angles between them (in degrees), in following order: [len(a), len(b), len(c), angle(b,c), angle(a,c), angle(a,b)]. First vector will lie in x-direction, second in xy-plane, and the third one in z-positive subspace. Default value: [0, 0, 0].

  • celldisp (Vector) – Unit cell displacement vector. To visualize a displaced cell around the center of mass of a Systems of qbits. Default value = (0,0,0)

  • pbc (one or three bool) – Periodic boundary conditions flags. Examples: True, False, 0, 1, (1, 1, 0), (True, False, False). Default value: False.

  • constraint (constraint object(s)) – Used for applying one or more constraints during structure optimization.

  • calculator (calculator object) – Used to attach a calculator for doing computation.

  • info (dict of key-value pairs) – Dictionary of key-value pairs with additional information about the system. The following keys may be used by ase:

    • spacegroup: Spacegroup instance

    • unit_cell: ‘conventional’ | ‘primitive’ | int | 3 ints

    • adsorbate_info: Information about special adsorption sites

    Items in the info attribute survives copy and slicing and can be stored in and retrieved from trajectory files given that the key is a string, the value is JSON-compatible and, if the value is a user-defined object, its base class is importable. One should not make any assumptions about the existence of keys.

Examples

Empty Qbits object:

>>> qs = qse.Qbits()

These are equivalent:

>>> a = qse.Qbits(
...     labels=['qb1', 'qb2'],
...     positions=np.array([(0, 0, 0), (0, 0, 2)])
... )
>>> a = qse.Qbits.from_qbit_list(
...     [Qbit('qb1', position=(0, 0, 0)), Qbit('qb2', position=(0, 0, 2))]
... )
>>> xd = np.array(
...    [[0, 0, 0],
...     [0.5, 0.5, 0.5]])
>>> qdim = qse.Qbits(positions=xd)
>>> qdim.cell = [1,1,1]
>>> qdim.pbc = True
>>> qlat = qdim.repeat([3,3,3])

The qdim will have shape = (2,1,1) and qlat will have shape = (6, 3, 3)

Notes

In order to do computation, a calculator object has to attached to the qbits object.

append(qbit)[source]#

Append qbit to end.

property calc#

Calculator object.

property cell#

The ase.cell.Cell for direct manipulation.

center_in_unit_cell(vacuum=None, axis=(0, 1, 2), about=None)[source]#

Center qbits in unit cell.

Centers the qbits in the unit cell, so there is the same amount of vacuum on all sides.

vacuum: float (default: None)

If specified adjust the amount of vacuum when centering. If vacuum=10.0 there will thus be 10 Angstrom of vacuum on each side.

axis: int or sequence of ints

Axis or axes to act on. Default: Act on all axes.

about: float or array (default: None)

If specified, center the qbits about <about>. I.e., about=(0., 0., 0.) (or just “about=0.”, interpreted identically), to center about the origin.

property constraints#

Constraints of the qbits.

copy()[source]#

Return a copy.

draw(radius=None, show_labels=False, colouring=None, units=None)[source]#

Visualize the positions of a set of qubits.

Parameters:
  • radius (float | str) – A cutoff radius for visualizing bonds. Pass ‘nearest’ to set the radius to the smallest distance between the passed qubits. If no value is passed the bonds will not be visualized.

  • show_labels (bool) – Whether to show the labels of the qubits. Defaults to False.

  • colouring (str | list) – A set of integers used to assign different colors to each Qubit. This can be used to view different magnetic orderings. Must have the same length as the number of Qubits.

  • units (str, optional) – The units of distance.

See also

qse.draw

euler_rotate(phi=0.0, theta=0.0, psi=0.0, center=(0, 0, 0))[source]#

Rotate qbits via Euler angles (in degrees).

Parameters:
  • phi (float) – The 1st rotation angle around the z axis.

  • theta (float) – Rotation around the x axis.

  • psi (float) – 2nd rotation around the z axis.

  • center – The point to rotate about. A sequence of length 3 with the coordinates, or ‘COM’ to select the center of mass, ‘COP’ to select center of positions or ‘COU’ to select center of cell.

Notes

Let

\[\begin{split}R = \begin{pmatrix} \cos(\psi ) & \sin(\psi ) & 0 \\ -\sin(\psi ) & \cos(\psi ) & 0\\ 0 & 0 & 1\\ \end{pmatrix} \begin{pmatrix} 1 & 0 & 0\\ 0 & \cos(\theta ) & \sin(\theta ) \\ 0 & -\sin(\theta ) & \cos(\theta ) \\ \end{pmatrix} \begin{pmatrix} \cos(\phi ) & \sin(\phi ) & 0 \\ -\sin(\phi ) & \cos(\phi ) & 0\\ 0 & 0 & 1\\ \end{pmatrix}\end{split}\]

then if \(\textbf{r}\) is a coordinate vector and \(\textbf{c}\) is the center, this transforms the coordinate vector to

\[\textbf{r} \rightarrow R(\textbf{r}-\textbf{c}) + \textbf{c}.\]
extend(other)[source]#

Extend qbits object by appending qbits from other.

classmethod fromdict(dct)[source]#

Rebuild qbits object from dictionary representation (todict).

get_all_distances()[source]#

Return the distances of all of the qubits with all of the other qubits.

Returns:

np.ndarray – An array of shape (nqbits, nqbits) containing the distances.

get_angle(i: int, j: int, k: int)[source]#

Get the angle in degress formed by three qubits.

Parameters:
  • i (int) – The index of the first qubit.

  • j (int) – The index of the second qubit.

  • k (int) – The index of the third qubit.

Returns:

float – The angle between the qubits.

Notes

Let x1, x2, x3 be the vectors describing the positions of the three qubits. Then we calcule the angle between x1-x2 and x3-x2.

get_angles(indices)[source]#

Get the angle in degress formed by three qubits for multiple groupings.

Parameters:

indices (list | np.ndarray) – The indices of the groupings of qubits. Must be of shape (n, 3), where n is the number of groupings.

Returns:

np.ndarray – The angles between the qubits.

Notes

Let x1, x2, x3 be the vectors describing the positions of the three qubits. Then we calcule the angle between x1-x2 and x3-x2 for all the different groupings.

get_array(name, copy=True)[source]#

Get an array.

Returns a copy unless the optional argument copy is false.

get_cell(complete=False)[source]#

Get the three unit cell vectors as a class:ase.cell.Cell` object.

The Cell object resembles a 3x3 ndarray, and cell[i, j] is the jth Cartesian coordinate of the ith cell vector.

get_cell_lengths_and_angles()[source]#

Get unit cell parameters. Sequence of 6 numbers.

First three are unit cell vector lengths and second three are angles between them:

[len(a), len(b), len(c), angle(b,c), angle(a,c), angle(a,b)]

in degrees.

get_celldisp()[source]#

Get the unit cell displacement vectors.

get_centroid()[source]#

Get the centroid of the positions.

Returns:

np.ndarray – The centroid of the positions.

Notes

For a set of \(k\) positions \(\textbf{x}_1, \textbf{x}_2, ..., \textbf{x}_k\) the centroid is given by

\[\frac{\textbf{x}_1 + \textbf{x}_2 + ... + \textbf{x}_k}{k}.\]
get_dihedral(a0, a1, a2, a3, mic=False)[source]#

Calculate dihedral angle.

Calculate dihedral angle (in degrees) between the vectors a0->a1 and a2->a3.

Use mic=True to use the Minimum Image Convention and calculate the angle across periodic boundaries.

get_dihedrals(indices, mic=False)[source]#

Calculate dihedral angles.

Calculate dihedral angles (in degrees) between the list of vectors a0->a1 and a2->a3, where a0, a1, a2 and a3 are in each row of indices.

Use mic=True to use the Minimum Image Convention and calculate the angles across periodic boundaries.

get_distance(i, j)[source]#

Return the distance between two qbits.

Parameters:
  • i (int) – The index of the first qubit.

  • j (int) – The index of the second qubit.

Returns:

float – The distance between the qubits.

get_distances(i, indices)[source]#

Return distances of the ith qubit with a list of qubits.

Parameters:
  • i (int) – The index of the ith qubit.

  • indices (list[int]) – The indices of other qubits.

Returns:

np.ndarray – An array containing the distances.

get_pbc()[source]#

Get periodic boundary condition flags.

get_properties(properties)[source]#

This method is experimental; currently for internal use.

get_reciprocal_cell()[source]#

Get the three reciprocal lattice vectors as a 3x3 ndarray.

Note that the commonly used factor of 2 pi for Fourier transforms is not included here.

get_scaled_positions(wrap=True)[source]#

Get positions relative to unit cell.

If wrap is True, qbits outside the unit cell will be wrapped into the cell in those directions with periodic boundary conditions so that the scaled coordinates are between zero and one.

If any cell vectors are zero, the corresponding coordinates are evaluated as if the cell were completed using cell.complete(). This means coordinates will be Cartesian as long as the non-zero cell vectors span a Cartesian axis or plane.

get_volume()[source]#

Get volume of unit cell.

has(name)[source]#

Check for existence of array.

name must be one of: ‘momenta’, ‘masses’, ‘initial_magmoms’, ‘initial_charges’.

property labels#

Attribute for direct manipulation of labels

new_array(name, a, dtype=None, shape=None)[source]#

Add new array.

If shape is not None, the shape of a will be checked.

property pbc#

Reference to pbc-flags for in-place manipulations.

pop(i=-1)[source]#

Remove and return qbit at index i (default last).

property positions#

Attribute for direct manipulation of the positions.

rattle(stdev=0.001, seed=None, rng=None)[source]#

Randomly displace qbits.

This method adds random displacements to the qbit positions, taking a possible constraint into account. The random numbers are drawn from a normal distribution of standard deviation stdev.

For a parallel calculation, it is important to use the same seed on all processors!

repeat(rep)[source]#

Create new repeated qbits object.

The rep argument should be a sequence of three positive integers like (2,3,1) or a single integer (r) equivalent to (r,r,r).

rotate(a, v='z', center=(0, 0, 0), rotate_cell=False)[source]#

Rotate qbits based on a vector and an angle, or two vectors.

Parameters:
  • a – Angle that the qbits is rotated (anticlockwise) around the vector ‘v’. ‘a’ can also be a vector and then ‘a’ is rotated into ‘v’. If ‘a’ is an angle it must be in degrees.

  • v – Vector to rotate the qbits around. Vectors can be given as strings: ‘x’, ‘-x’, ‘y’, … . Defaults to ‘z’.

  • center – The center is kept fixed under the rotation. Use ‘COP’ to fix the center of positions or ‘COU’ to fix the center of cell. Defaults to = (0, 0, 0).

  • rotate_cell = False – If true the cell is also rotated.

Examples

The following all rotate 90 degrees anticlockwise around the z-axis, so that the x-axis is rotated into the y-axis:

>>> qbits.rotate(90)
>>> qbits.rotate(90, 'z')
>>> qbits.rotate(90, (0, 0, 1))
>>> qbits.rotate(-90, '-z')
>>> qbits.rotate('x', 'y')
>>> qbits.rotate((1, 0, 0), (0, 1, 0))

Notes

If ‘a’ is an angle, \(\theta\), and if \(\textbf{v}\) is the vector then we define

\[R = \cos(\theta)I + \sin(\theta)[\textbf{v}]_\times + (1-\cos(\theta))\textbf{v}\textbf{v}^T\]

where \([\textbf{v}]_\times \textbf{x} = \textbf{v} \times \textbf{x}\). If \(\textbf{r}\) is a coordinate vector and \(\textbf{c}\) is the center, this transforms the coordinate vector to

\[\textbf{r} \rightarrow R(\textbf{r}-\textbf{c}) + \textbf{c}.\]
rotate_dihedral(a1, a2, a3, a4, angle=None, mask=None, indices=None)[source]#

Rotate dihedral angle.

Same usage as in ase.Qbits.set_dihedral(): Rotate a group by a predefined dihedral angle, starting from its current configuration.

set_angle(a1, a2=None, a3=None, angle=None, mask=None, indices=None, add=False)[source]#

Set angle (in degrees) formed by three qbits.

Sets the angle between vectors a2->*a1* and a2->*a3*.

If add is True, the angle will be changed by the value given.

Same usage as in ase.Qbits.set_dihedral(). If mask and indices are given, indices overwrites mask. If mask and indices are not set, only a3 is moved.

set_array(name, a, dtype=None, shape=None)[source]#

Update array.

If shape is not None, the shape of a will be checked. If a is None, then the array is deleted.

set_cell(cell, scale_qbits=False, apply_constraint=True)[source]#

Set unit cell vectors.

Parameters:

cell: 3x3 matrix or length 3 or 6 vector

Unit cell. A 3x3 matrix (the three unit cell vectors) or just three numbers for an orthorhombic cell. Another option is 6 numbers, which describes unit cell with lengths of unit cell vectors and with angles between them (in degrees), in following order: [len(a), len(b), len(c), angle(b,c), angle(a,c), angle(a,b)]. First vector will lie in x-direction, second in xy-plane, and the third one in z-positive subspace.

scale_qbits: bool

Fix qbit positions or move qbits with the unit cell? Default behavior is to not move the qbits (scale_qbits=False).

apply_constraint: bool

Whether to apply constraints to the given cell.

Examples:

Two equivalent ways to define an orthorhombic cell:

>>> qbits = Qbits('He')
>>> a, b, c = 7, 7.5, 8
>>> qbits.set_cell([a, b, c])
>>> qbits.set_cell([(a, 0, 0), (0, b, 0), (0, 0, c)])

FCC unit cell:

>>> qbits.set_cell([(0, b, b), (b, 0, b), (b, b, 0)])

Hexagonal unit cell:

>>> qbits.set_cell([a, a, c, 90, 90, 120])

Rhombohedral unit cell:

>>> alpha = 77
>>> qbits.set_cell([a, a, a, alpha, alpha, alpha])
set_celldisp(celldisp)[source]#

Set the unit cell displacement vectors.

set_centroid(centroid)[source]#

Set the centroid of the positions.

Parameters:

centroid (float | np.ndarray) – The new centroid. Can be a float or a xyz vector

Notes

For a set of \(k\) positions \(\textbf{x}_1, \textbf{x}_2, ..., \textbf{x}_k\) the centroid is given by

\[\frac{\textbf{x}_1 + \textbf{x}_2 + ... + \textbf{x}_k}{k}.\]
set_constraint(constraint=None)[source]#

Apply one or more constrains.

The constraint argument must be one constraint object or a list of constraint objects.

set_dihedral(a1, a2, a3, a4, angle, mask=None, indices=None)[source]#

Set the dihedral angle (degrees) between vectors a1->a2 and a3->a4 by changing the qbit indexed by a4.

If mask is not None, all the qbits described in mask (read: the entire subgroup) are moved. Alternatively to the mask, the indices of the qbits to be rotated can be supplied. If both mask and indices are given, indices overwrites mask.

Important: If mask or indices is given and does not contain a4, a4 will NOT be moved. In most cases you therefore want to include a4 in mask/indices.

Example: the following defines a very crude ethane-like molecule and twists one half of it by 30 degrees.

>>> qbits = Qbits('HHCCHH', [[-1, 1, 0], [-1, -1, 0], [0, 0, 0],
...                          [1, 0, 0], [2, 1, 0], [2, -1, 0]])
>>> qbits.set_dihedral(1, 2, 3, 4, 210, mask=[0, 0, 0, 1, 1, 1])
set_distance(a0, a1, distance, fix=0.5, mic=False, mask=None, indices=None, add=False, factor=False)[source]#

Set the distance between two qbits.

Set the distance between qbits a0 and a1 to distance. By default, the center of the two qbits will be fixed. Use fix=0 to fix the first qbit, fix=1 to fix the second qbit and fix=0.5 (default) to fix the center of the bond.

If mask or indices are set (mask overwrites indices), only the qbits defined there are moved (see ase.Qbits.set_dihedral()).

When add is true, the distance is changed by the value given. In combination with factor True, the value given is a factor scaling the distance.

It is assumed that the qbits in mask/indices move together with a1. If fix=1, only a0 will therefore be moved.

set_pbc(pbc)[source]#

Set periodic boundary condition flags.

set_scaled_positions(scaled)[source]#

Set positions relative to unit cell.

property shape#

The shape of the qbits

property states#

Attribute for direct manipulation of the states.

todict()[source]#

For basic JSON (non-database) support.

translate(displacement)[source]#

Translate qbit positions.

Parameters:

displacement (float | np.ndarray) – The displacement argument can be a float an xyz vector or an nx3 array (where n is the number of qbits).

wrap(**wrap_kw)[source]#

Wrap positions to unit cell.

Parameters:

wrap_kw: (keyword=value) pairs

optional keywords pbc, center, pretty_translation, eps, see ase.geometry.wrap_positions()

write(filename, format=None, **kwargs)[source]#

Write qbits object to a file.

see ase.io.write for formats. kwargs are passed to ase.io.write.

class qse.Signal(values, duration=None)[source]#

The Signal class represents a 1D signal with values and duration.

Parameters:
  • values (list | np.ndarray) – The values of the signal.

  • duration (int) – Duration of the signal. Defaults to the length of the passed values.

Examples

One can create a signal by passing an array of values:

>>> qse.Signal([1, 2, 3], 100)
... Signal(duration=100, values=[1. 2. 3.])

Arithmetic operations with scalars is supported. Adding or multiplying a scalar to a Signal returns a new Signal with modified values and the same duration. For example:

>>> signal = qse.Signal([1, 1])
>>> signal * 3 + 0.5
... Signal(duration=2, values=[3.5 3.5])

Two Signals can be added together which concatenates their values and sums their durations. So if w1, w2 are instantiation of Signal, then w = w1 + w2 gives signal with concatenated values, i.e., w.values = [w1.values, w2.values], and added duration w.duration = w1.duration + w2.duration. For example:

>>> signal_1 = qse.Signal([1, 1], 5)
>>> signal_2 = qse.Signal([2, 2], 2)
>>> signal_1 + signal_2
... Signal(duration=7, values=[1. 1. 2. 2.])

Notes

Currently, the object gets created for multi-dim arrays as well. However, it should be used for 1D only, we haven’t made it useful or consistent for multi-dim usage.

qse.draw(qbits, radius=None, show_labels=False, colouring=None, units=None)[source]#

Visualize the positions of a set of qubits.

Parameters:
  • qbits (qse.Qbits) – The Qbits object.

  • radius (float | str) – A cutoff radius for visualizing bonds. Pass ‘nearest’ to set the radius to the smallest distance between the passed qubits. If no value is passed the bonds will not be visualized.

  • show_labels (bool) – Whether to show the labels of the qubits. Defaults to False.

  • colouring (str | list) – A set of integers used to assign different colors to each Qubit. This can be used to view different magnetic orderings. Must have the same length as the number of Qubits.

  • units (str, optional) – The units of distance.

qse.calc#

Interface to different QSE calculators.

exception qse.calc.CalculationFailed[source]#

Calculation failed unexpectedly.

Reasons to raise this error are:
  • Calculation did not converge

  • Calculation ran out of memory

  • Segmentation fault or other abnormal termination

  • Arithmetic trouble (singular matrices, NaN, …)

Typically raised during calculation.

class qse.calc.Calculator(is_calculator_available: bool, installation_message: str, **kwargs)[source]#

Base-class for all QSE calculators, adapted from ASE calculators.

A calculator must raise PropertyNotImplementedError if asked for a property that it can’t calculate. So, if calculation of the stress tensor has not been implemented, get_stress(qbits) should raise PropertyNotImplementedError. This can be achieved simply by not including the string ‘stress’ in the list implemented_properties which is a class member. These are the names of the standard properties: ‘energy’, ‘forces’, ‘stress’, ‘dipole’, ‘charges’, ‘magmom’ and ‘magmoms’.

calculate(qbits=None, properties=['energy'], system_changes=['labels', 'positions', 'states', 'cell', 'pbc'])[source]#

Do the calculation.

Parameters:
  • properties (list of str) – List of what needs to be calculated. Can be any combination of ‘energy’, ‘forces’, ‘stress’, ‘dipole’, ‘charges’, ‘magmom’ and ‘magmoms’.

  • system_changes (list of str) – List of what has changed since last calculation. Can be any combination of these six: ‘positions’, ‘numbers’, ‘cell’, ‘pbc’, ‘initial_charges’ and ‘initial_magmoms’.

  • Subclasses need to implement this, but can ignore properties

  • and system_changes if they want. Calculated properties should

  • be inserted into results dictionary like shown in this dummy

  • example::

    self.results = {‘energy’: 0.0,

    ‘forces’: np.zeros((len(qbits), 3)), ‘stress’: np.zeros(6), ‘dipole’: np.zeros(3), ‘charges’: np.zeros(len(qbits)), ‘magmom’: 0.0, ‘magmoms’: np.zeros(len(qbits))}

  • The subclass implementation should first call this

  • implementation to set the qbits attribute and create any missing

  • directories.

calculate_properties(qbits, properties)[source]#

This method is experimental; currently for internal use.

check_state(qbits, tol=1e-15)[source]#

Check for any system changes since last calculation.

default_parameters: Dict[str, Any] = {}#

Default parameters

discard_results_on_any_change = False#

Whether we purge the results following any change in the set() method.

get_sij()[source]#

Get spin correlation s_ij. If the hamiltonian isn’t simulated, it triggers simulation first.

Returns:

np.ndarray – Array of NxN shape containing spin correlations.

See also

qse.magnetic.get_sij

get_spins()[source]#

Get spin expectation values. If the hamiltonian isn’t simulated, it triggers simulation first.

Returns:

np.ndarray – Array of Nx3 containing spin expectation values.

ignored_changes: Set[str] = {}#

Properties of Qbits which we ignore for the purposes of cache

implemented_properties: List[str] = []#

Properties calculator can handle (energy, forces, …)

read(label)[source]#

Read qbits, parameters and calculated properties from output file.

Read result from self.label file. Raise ReadError if the file is not there. If the file is corrupted or contains an error message from the calculation, a ReadError should also be raised. In case of succes, these attributes must set:

qbits: Qbits object

The state of the qbits from last calculation.

parameters: Parameters object

The parameter dictionary.

results: dict

Calculated properties like energy and forces.

The FileIOCalculator.read() method will typically read qbits and parameters and get the results dict by calling the read_results() method.

reset()[source]#

Clear all information from old calculation.

set(**kwargs)[source]#

Set parameters like set(key1=value1, key2=value2, …).

A dictionary containing the parameters that have been changed is returned.

Subclasses must implement a set() method that will look at the chaneged parameters and decide if a call to reset() is needed. If the changed parameters are harmless, like a change in verbosity, then there is no need to call reset().

The special keyword ‘parameters’ can be used to read parameters from a file.

structure_factor_from_sij(L1: int, L2: int, L3: int)[source]#

Get the structure factor.

Parameters:
  • L1 (int) – Extent of lattice in x direction.

  • L2 (int) – Extent of lattice in y direction.

  • L3 (int) – Extent of lattice in z direction.

Returns:

np.ndarray – Array containing the structure factor.

exception qse.calc.CalculatorSetupError[source]#

Calculation cannot be performed with the given parameters.

Reasons to raise this errors are:
  • The calculator is not properly configured (missing executable, environment variables, …)

  • The given qbits object is not supported

  • Calculator parameters are unsupported

Typically raised before a calculation.

class qse.calc.Myqlm(qbits=None, amplitude=None, detuning=None, duration=None, qpu=None, analog=True, system='rydberg', label='myqlm-run', wtimes=True)[source]#

QSE-Calculator for MyQLM

Parameters:
  • qbits – …

  • amplitude – …

  • detuning – …

  • duration – …

  • qpu – …

  • analog – …

  • system – …

  • label – …

  • wtimes – …

calculate(qbits=None, properties=Ellipsis, system_changes=Ellipsis)[source]#

_summary_

Parameters:
  • qbits (_type_, optional) – _description_, by default None

  • properties (_type_, optional) – _description_, by default …

  • system_changes (_type_, optional) – _description_, by default …

default_parameters: Dict[str, Any] = {'label': 'q', 'qbits': None}#

Default parameters

implemented_properties: List[str] = ['energy', 'state', 'fidality']#

Properties calculator can handle (energy, forces, …)

exception qse.calc.PropertyNotImplementedError[source]#

Raised if a calculator does not implement the requested property.

exception qse.calc.PropertyNotPresent[source]#

Requested property is missing.

Maybe it was never calculated, or for some reason was not extracted with the rest of the results, without being a fatal ReadError.

class qse.calc.Pulser(qbits=None, amplitude=None, detuning=None, device=None, emulator=None, label='pulser-run', wtimes=True)[source]#

QSE-Calculator for pulser.

Parameters:
  • amplitude (qse.Signal, pulser.waveforms.Waveform) – The amplitude pulse.

  • detuning (qse.Signal, pulser.waveforms.Waveform) – The detuning pulse.

  • qbits (qse.Qbits) – The qbits object.

  • device (pulser.devices.Device) – The device. Defaults to pulser.devices.MockDevice.

  • emulator – The emulator. Defaults to QutipEmulator.

  • label (str) – The label. Defaults to “pulser-run”.

  • wtimes (bool) – Whether to print the times. Defaults to True.

Examples

A simple example of using the Pulser calculator:

>>> qbits = qse.lattices.chain(4.0, 4)
>>> duration = 400
>>> pulser_calc = qse.calc.Pulser(
...     amplitude=qse.Signal(np.ones(6) * 1.01, duration),
...     detuning=qse.Signal(np.ones(6) * 0.12, duration),
...     qbits=qbits,
... )
>>> pulser_calc.build_sequence()
>>> pulser_calc.calculate()
>>> pulser_calc.get_spins()

Notes

Pulser will only use the x-y coordinates of the Qbits object.

Pulser is an open-source Python software package. It provides easy-to-use libraries for designing and simulating pulse sequences that act on programmable arrays of neutral qbits, a promising platform for quantum computation and simulation. Online documentation: https://pulser.readthedocs.io White paper: Quantum 6, 629 (2022) Source code: pasqal-io/Pulser License: Apache 2.0 - see [LICENSE](pasqal-io/Pulser) for details.

build_sequence()[source]#

Build the sequence of operations involving the qubit coordinates, amplitude pulse and detuning pulse.

calculate(progress=True)[source]#

Do the calculation. # system_changes=all_changes -> check it’s relevance.

implemented_properties: List[str] = ['energy', 'state', 'fidality']#

Properties calculator can handle (energy, forces, …)

qse.lattices#

A collection of convenience functions for creating common lattices.

qse.lattices.chain(lattice_spacing: float, repeats: int) Qbits[source]#

Generate a Qbits object in linear chain geometry.

Parameters:
  • lattice_spacing (float) – The lattice spacing.

  • repeats (int) – The number of repeats. Must be greater than 1.

Returns:

Qbits – The Qbits lattice.

qse.lattices.hexagonal(lattice_spacing: float, repeats_x: int, repeats_y: int) Qbits[source]#

Generate a Qbits object in hexagonal lattice geometry.

Parameters:
  • lattice_spacing (float) – The lattice spacing.

  • repeats_x (int) – The number of repeats in the x direction. Must be greater than 1.

  • repeats_y (int) – The number of repeats in the y direction. Must be greater than 1.

Returns:

Qbits – The Qbits lattice.

qse.lattices.kagome(lattice_spacing: float, repeats_x: int, repeats_y: int) Qbits[source]#

Generate a Qbits object in kagome lattice geometry.

Parameters:
  • lattice_spacing (float) – The lattice spacing.

  • repeats_x (int) – The number of repeats in the x direction. Must be greater than 1.

  • repeats_y (int) – The number of repeats in the y direction. Must be greater than 1.

Returns:

Qbits – The Qbits lattice.

qse.lattices.ring(spacing: float, nqbits: int) Qbits[source]#

Generate a Qbits object in a ring geometry.

Parameters:
  • radius (float) – The spacing between the qubits.

  • nqbits (int) – Number of qubits on the ring.

Returns:

Qbits – The Qbits object.

qse.lattices.square(lattice_spacing: float, repeats_x: int, repeats_y: int) Qbits[source]#

Generate a Qbits object in square lattice geometry.

Parameters:
  • lattice_spacing (float) – The lattice spacing.

  • repeats_x (int) – The number of repeats in the x direction. Must be greater than 1.

  • repeats_y (int) – The number of repeats in the y direction. Must be greater than 1.

Returns:

Qbits – The Qbits lattice.

qse.lattices.torus(n_outer: int, n_inner: int, inner_radius: float, outer_radius: float) Qbits[source]#

Generate a Qbits object in a torus geometry.

Parameters:
  • n_outer (int) – Number of points in larger (outer) dimension.

  • n_inner (int) – Number of points in smaller (inner) dimension.

  • inner_radius (float) – The inner radius.

  • outer_radius (float) – The outer radius.

Returns:

Qbits – The Qbits object.

qse.lattices.triangular(lattice_spacing: float, repeats_x: int, repeats_y: int) Qbits[source]#

Generate a Qbits object in triangular lattice geometry.

Parameters:
  • lattice_spacing (float) – The lattice spacing.

  • repeats_x (int) – The number of repeats in the x direction. Must be greater than 1.

  • repeats_y (int) – The number of repeats in the y direction. Must be greater than 1.

Returns:

Qbits – The Qbits lattice.

qse.magnetic#

Functions for computing magnetic correlation

qse.magnetic.get_basis(nqbits: int, hsize: int = None)[source]#

Returns a boolean array representing basis in qubit product state. Originally it is intended for the full qubit space, for which hsize = \(2^N\), however if we need a subset of the full, then hsize can be smaller.

Parameters:
  • nqbits (int) – The number of qubits, \(N\).

  • hsize (int, optional) – The size of the hamiltonian or hilbert space. Defaults to the full Hilbert space, \(2^N\).

Returns:

np.ndarray – The basis of shape (hsize, N).

qse.magnetic.get_number_operator(statevector: ndarray[complex], nqbits: int, ibasis: ndarray[bool] = None) ndarray[float][source]#

Get the expectation value of the number operators.

Parameters:
  • statevector (np.ndarray[complex]) – \(2^N\) sized complex array representing the statevector.

  • nqbits (int) – Number of Qubits or Spins, \(N\).

  • ibasis (np.ndarray[bool], optional) – Boolean array representing product basis for qubits passed for computing. Defaults to the full Hilbert space.

Returns:

np.ndarray[float] – An N array with expectation values of the number operators.

Notes

The number operator for qubit \(i\) is given by \(n_i|b_1,...,b_i,...,b_N\rangle=b_i|b_1,...,b_i,...,b_N\rangle\). This function returns the vector \(\langle\psi|n_i|\psi\rangle\).

qse.magnetic.get_sisj(statevector: ndarray[complex], nqbits: int, ibasis: ndarray[bool] = None) ndarray[float][source]#

Compute the spin correlation function \(S_{ij} = \langle\psi| S_i \cdot S_j |\psi\rangle\).

Parameters:
  • statevector (np.ndarray[complex]) – \(2^N\) sized complex array representing the statevector.

  • nqbits (int) – Number of Qubits or Spins, \(N\).

  • ibasis (np.ndarray[bool], optional) – Boolean array representing product basis for qubits passed for computing. Defaults to the full Hilbert space.

Returns:

np.ndarray[float] – An NxN array with computed expectation value of \(\langle S_i \cdot S_j\rangle\).

Notes

With a list of qubits seen as spin 1/2 objects, the spins operators are \(S_i = (S_x, S_y, S_z)\). The state \(|\psi\rangle\) is given as follows: \(|\psi\rangle = \sum_i \text{statevector}[i] \, \text{ibasis}[i]\).

qse.magnetic.get_spins(statevector: ndarray[complex], nqbits: int, ibasis: ndarray[bool] = None) ndarray[float][source]#

Get the expectation value of the spin operators \((S_x, S_y, S_z)\).

Parameters:
  • statevector (np.ndarray[complex]) – \(2^N\) sized complex array representing the statevector.

  • nqbits (int) – Number of Qubits or Spins, \(N\).

  • ibasis (np.ndarray[bool], optional) – Boolean array representing product basis for qubits passed for computing. Defaults to the full Hilbert space.

Returns:

np.ndarray[float] – An Nx3 array with expectation values of spin operator.

Notes

With a list of qubits seen as spin 1/2 object, here one calculates the expectation value \(\langle\psi| (S_x, S_y, S_z) |\psi\rangle\). The state is given as follows: \(|\psi\rangle = \sum_i \text{statevector}[i] \, \text{ibasis}[i]\).

qse.magnetic.structure_factor_from_sij(L1: int, L2: int, L3: int, qbits: Qbits, s_ij: ndarray[float]) ndarray[float][source]#

Computes the structure factor from the spin correlation. The structure factor is just fourier transform of the \(S_{ij}\) with:

\[S[q] = \frac{1}{N^2} \sum_{ij} S_{ij} \exp{i q \cdot (x_i - x_j)}.\]

The (L1, L2, L3) are passed as shape of the lattice, and there is a qubit at each of these lattice sites.

Parameters:
  • L1 (int) – Extent of lattice in x direction.

  • L2 (int) – Extent of lattice in y direction.

  • L3 (int) – Extent of lattice in z direction.

  • qbits (qse.Qbits) – The Qbits object representing the lattice.

  • s_ij (np.ndarray[float]) – The array with spin correlation.

Returns:

np.ndarray[float] – Returns the structure factor.

qse.utils#

Utility functions for a variety of usage within and outside of QSE.

qse.utils.int2bin(x, width=32)[source]#

Converts an integer array to array of equivalent binary strings.

Parameters:
  • x (np.ndarray) – An array of integers.

  • width (int) – The length of the binary strings.

Returns:

np.ndarray – The array of binary strings.

Notes

This function is equivalent to:

>>> int2bin = np.vectorize(lambda x, width=16: np.binary_repr(x,width=width))

However vectorize version is a bit slower compared to the one below.

qse.utils.print_environment()[source]#

Print the Python and qse version of the environment.

Indices and tables#