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, calculator=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].

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

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

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.

copy()[source]#

Return a copy.

draw(radius=None, show_labels=False, colouring=None, units=None, equal_aspect=True)[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.

  • equal_aspect (bool, optional) – Whether to have the same scaling for the axes. Defaults to True.

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_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_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_reciprocal_cell()[source]#

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

Returns:

np.ndarray – The reciprocal cell.

Notes

The commonly used factor of 2 pi for Fourier transforms is not included here.

get_volume()[source]#

Get volume of unit cell.

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. 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}.\]
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)[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).

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_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_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.

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, equal_aspect=True)[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.

  • equal_aspect (bool, optional) – Whether to have the same scaling for the axes. Defaults to True.

qse.calc#

Interface to different QSE calculators.

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

Base-class for all QSE calculators.

Parameters:
  • label (str) – Name used for all files. Not supported by all calculators. May contain a directory, but please use the directory parameter for that instead.

  • qbits (Qbits object) – Optional Qbits object to which the calculator will be attached. When restarting, qbits will get its positions and unit-cell updated from file.

calculate()[source]#

Do the calculation.

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.

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.

class qse.calc.ExactSimulator(amplitude=None, detuning=None)[source]#

A calculator that evoles the qubit system exactly. Only supported for a single qubit.

Parameters:
  • amplitude (qse.Signal) – The amplitude pulse.

  • detuning (qse.Signal) – The detuning pulse.

Notes

For a single qubit the Hamiltonian is

\[H = \frac{\Omega}{2} e^{-i\phi}|0\rangle\langle 1| + \frac{\Omega}{2} e^{i\phi}|0\rangle\langle 1| -\delta|1\rangle\langle 1|\]

where \(\Omega\) is the amplitude, \(\phi\) the phase and \(\delta\) the detuning. Setting the phase to zero and adding a constant \(I\delta/2\) we get

\[H = \frac{\Omega X + \delta Z}{2}\]

Then the time evolution unitary is given by

\[U(t) = e^{-iH t} = \cos(\Delta t/2) I - i \sin(\Delta t/2) \frac{\Omega X + \delta Z}{\Delta}\]

Where \(\Delta=\sqrt{\delta^2+\Omega^2}\).

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

QSE-Calculator for MyQLM.

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

  • amplitude (qse.Signal) – The amplitude pulse.

  • detuning (qse.Signal) – The detuning pulse.

  • qpu (qat.qpus) – The Quantum Processing Unit for executing the job.

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

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

calculate()[source]#

Run the calculation.

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

QSE-Calculator for pulser.

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

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

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

  • channel (str) – Which channel to use. For example “rydberg_global” for Rydberg or “mw_global” for microwave. Defaults to “rydberg_global”.

  • magnetic_field (np.ndarray | list) – A magnetic field. Must be a 3-component array or list. Can only be passed when using the Microwave channel (“mw_global”).

  • 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(
...     qbits=qbits,
...     amplitude=qse.Signal(np.ones(6) * 1.01, duration),
...     detuning=qse.Signal(np.ones(6) * 0.12, duration),
... )
>>> 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]#

Run the calculation.

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.

qse.visualise#

qse.visualise.draw(qbits, radius=None, show_labels=False, colouring=None, units=None, equal_aspect=True)[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.

  • equal_aspect (bool, optional) – Whether to have the same scaling for the axes. Defaults to True.

qse.visualise.view_matrix(matrix, labels_x=None, labels_y=None, vcenter=None)[source]#

Visualise a matrix.

Parameters:
  • matrix (np.ndarray) – The matrix to be visualised.

  • labels_x (list, optional) – Labels to be displayed on the x axis.

  • labels_y (list, optional) – Labels to be displayed on the y axis.

  • vcenter (float, optional) – The center of the colorbar.

Indices and tables#