Tools#

Set of tools that are useful for circuit- and operation-creation.

Contains a set of modules with helper functions for generation of different unitaries as well as labels and unique ID’s that are used when constructing primitives such as qubits and bits.

Counters Module#

class IDCounter[source]#

Bases: object

ID number counter.

Generates pseudo-random alphanumeric ID numbers with a certain length in batches. If all ID numbers have been used in a batch, a new batch is generated. If all ID numbers of the declared length has been used, the length is incremented by one and ID numbers of the new length is generated instead.

batch = 1000[source]#
id_set = {}[source]#
length = 4[source]#
classmethod next() str[source]#

Returns a semi-random (unique) alphanumeric ID.

classmethod refresh() None[source]#

Refreshes the set of available ID numbers; automatically done when necessary.

classmethod reset(length: int | None = None, batch: int | None = None) None[source]#

Resets the ID counter to use a certain length and/or batch size.

Parameters:
  • length – The (initial) length of unique ID numbers.

  • batch – The size of each generated batch of ID numbers. The lower the number, the less variation there will be between IDs; the higher the number, the more variation there will be, but with a higher memory and performance impact at refresh time.

Unitary Module#

build_controlled_unitary(control: Union[int, Sequence[int]], target: Union[int, Sequence[int]], unitary: NDArray, num_qubits: Optional[int] = None, dtype: DTypeLike = <class 'complex'>) NDArray[source]#

Build the unitary matrix for a controlled operation.

Parameters:
  • control – Index of control qubit(s).

  • target – Index of target qubit. Only a single target supported.

  • num_qubits – Total number of qubits.

Returns:

Unitary matrix representing the controlled operation.

Return type:

NDArray

build_unitary(circuit) NDArray[source]#

Builds the circuit unitary by multiplying together the operation matrices.

Parameters:

circuit – The circuit for which the unitary should be built.

Returns:

Unitary matrix representation of the circuit.

Return type:

NDArray