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.greedy_grouping(schedule)[source]#

Greedily groups schedule into maximally sized groups.

This function is designed to be used with the ordered output of get_time_series. Using this function with arbitrary schedules might not give optimal groupings.

Parameters:

schedule (List[List[int]]) – The ouput of the cfl counter in get_time_series

Returns:

Maximally grouped schedule

Return type:

List[List[int]]

qlbm.tools.utils.get_time_series(num_discrete_velocities, max_allowed_iters=10000, tolerance=1e-06, group_velocities=True)[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

  • group_velocities (bool, optional) – When True, runs greedy grouping before returning schedule

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(number_encoded, num_qubits)[source]#

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

Parameters:
  • number_encoded (int) – The integer representation of the number.

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

Returns:

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

Return type:

List[int]

class qlbm.tools.utils.ComparatorMode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Enumerator for the modes of quantum comparator circuits.

The modes are as follows:

  • (1, ComparatorMode.LT, \(<\));

  • (2, ComparatorMode.LE, \(\leq\));

  • (3, ComparatorMode.GT, \(>\));

  • (4, ComparatorMode.GE, \(\geq\)).

classmethod from_string(mode)[source]#

Parses inequality strings to ComparatorMode objects.

Parameters:

mode (str) – One of “>=”, “>”, “<=”, and “<”.

Returns:

The ComparatorMode representing the inequality

Return type:

ComparatorMode

to_string()[source]#

Get the string representation of this object.

Returns:

One of “<”, “<=”, “>”, “>=”.

Return type:

str

to_operator()[source]#

Get the Python comparison operator represented by this mode.

Returns:

The function taking to integers and returning a boolean representing the comparison of the integers.

Return type:

Callable[[int, int], bool]