Other Tools#

In addition to its core modules, qlbm offers several miscellaneous Exceptions and Utilities.

Exceptions#

Contains custom exceptions for the QLBM package.

exception qlbm.tools.exceptions.LatticeException(message)[source]#

Exception raised when encountering invalid or misaligned lattice properties.

Parameters:

message (str)

Return type:

None

exception qlbm.tools.exceptions.ResultsException(message)[source]#

Exception raised during the processing of QBMResults objects.

Parameters:

message (str)

Return type:

None

exception qlbm.tools.exceptions.CompilerException(message)[source]#

Exception raised when encountering a circuit compilation exception.

Parameters:

message (str)

Return type:

None

exception qlbm.tools.exceptions.CircuitException(message)[source]#

Exception raised when attempting to compile to an unsupported target.

Parameters:

message (str)

Return type:

None

exception qlbm.tools.exceptions.ExecutionException(message)[source]#

Exception raised when attempting to execute circuits with mismatched properties.

Parameters:

message (str)

Return type:

None

Utilities#

General qlbm utilities.

qlbm.tools.utils.create_directory_and_parents(directory)[source]#

Creates a given directory and all its parent directories.

Parameters:

directory (str) – The fully specified location of the directory.

Return type:

None

qlbm.tools.utils.qiskit_circuit_to_qulacs(circuit)[source]#

Converts a Qiskit QuantumCircuit to a Qulacs QuantumCircuit.

Conversion takes place by first converting the Qiskit circuit into its OpenQASM 2 representation. This representation is then parsed into a Qulacs circuit.

Parameters:
  • (QiskitQC) (circuit)

  • circuit (QuantumCircuit)

Returns:

QulacsQC

Return type:

The Qulacs counterpart to the QuantumCircuit.

qlbm.tools.utils.flatten(xss)[source]#

Flattens nested lists by one level.

Parameters:

xss (List[List[Any]]) – A nested list.

Returns:

The input flattened to by one level.

Return type:

List[Any]

qlbm.tools.utils.bit_value(num, position)[source]#

The value of the bit at a given position in a given integer.

Parameters:
  • num (int) – The number.

  • position (int) – The position in the binary representation.

Returns:

The velut of the target bit.

Return type:

int

qlbm.tools.utils.evaluate_qasm_rotation_string(qasm_repr)[source]#

Evaluate the symbolic values in a given qasm representation numerically.

Used a hacky way to convert between Qiskit and Qulacs representations.

Parameters:

qasm_repr (str) – A QASM string possibly containing symbolic values.

Returns:

The QASM string with symbolic values evaluated numerically.

Return type:

str

qlbm.tools.utils.get_circuit_properties(circuit)[source]#

Gets the static properties of a quantum circuit.

Parameters:

circuit (QiskitQC | QulacsQC) – The circuit for which to compile the properties.

Return type:

Tuple[str, int, int, int]

Returns:

Tuple[str, int, int, int]: The circuit’s platform, the number of qubits, depth, and number of gates of the circuit.

qlbm.tools.utils.qiskit_to_qulacs(circuit)[source]#

Converts a Qiskit quantum circuit to a Qulacs quantum circuit equivalent using Tket.

Parameters:

circuit (QiskitQC) – An arbitrary Qiskit circuit.

Returns:

The equivalent Qulacs circuit, if compatible.

Return type:

QulacsQC

qlbm.tools.utils.dimension_letter(dim)[source]#

Maps [0, 1, 2] to [x, y, z].

Parameters:
  • (int) (dim)

  • dim (int)

Return type:

str

Returns:

str: The letter associated with the dimension.

qlbm.tools.utils.is_two_pow(num)[source]#

Whether a number is a power of 2.

Parameters:
  • (int) (num)

  • num (int)

Return type:

bool

Returns:

bool: Whether the input is a power of 2.

qlbm.tools.utils.get_time_series(num_discrete_velocities, max_allowed_iters=10000, tolerance=1e-06)[source]#

Compute a time series of the streaming velocities for a given number of discrete velocities.

Parameters:
  • num_discrete_velocities (int) – The number of discrete velocities in the time series.

  • max_allowed_iters (int, optional) – The number of iterations before truncating the time series, by default 10000

  • tolerance (float, optional) – The level of precision required to truncate the time sries, by default 1e-6

Returns:

The order in which velocities have to be streamed before all particles have reached discrete gridpoints exactly

Return type:

List[List[int]]

qlbm.tools.utils.get_qubits_to_invert(gridpoint_encoded, num_qubits)[source]#

Returns the indices at which a given gridpoint encoded value has a 0. Inverting these indices results in a \(\ket{1}^{\otimes n}\) state.

Parameters:
  • gridpoint_encoded (int) – The integer representation of the gridpoint.

  • num_qubits (int) – The total nuimber of grid qubits.

Returns:

The indices of the (qu)bits that have value 0.

Return type:

List[int]