Base Classes#
For extendability and modularity purposes, qlbm
provides several base classes
with interfaces that aim to make the development of novel QLBM methods easier.
This page documents the base classes that have to do with the register
setup and quantum circuit generation.
The architecture of the inheritance hierarchy is two-fold:
vertically based on specificity (i.e., more specialized classes for specific QLBMs)
and horizontally based on methods (i.e., different implementations for different QLBMs).
Lattice Base#
- class qlbm.lattice.lattices.base.Lattice(lattice_data, logger=<Logger qlbm (WARNING)>)[source]#
Base class for all algorithm-specific Lattices.
A
Lattice
object performs the following functions:Parse high-level input from JSON files or Python dictionaries into appropriate quantum registers and other information used to infer quantum circuits.
Validate the soundness of the input information and raise warnings if algorithmic assumptions are violated.
Provide parameterized inputs for the inference of quantum circuits that comprise QLBMs.
The inheritance structure of
Lattice
s is such that each QLBM uses a specialized implementation of this base class. This allows the same parsing procedures to be used for all algorithms, while additional validity checks can be built on top. AllLattice
objects share the following attributes:Attribute
Summary
num_dims
The number of dimensions of the lattice.
num_gridpoints
A
List[int]
of the number of gridpoints of the lattice in each dimension. Important: for easier compatibility with binary arithmetic, the number of gridpoints specified in the input dicitionary is one larger than the one held in theLattice
. That is, for a16x64
lattice, thenum_gridpoints
attribute will have the value[15, 63]
.num_grid_qubits
The total number of qubits required to encode the lattice grid.
num_velocity_qubits
The total number of qubits required to encode the velocity discretization of the lattice.
num_ancilla_qubits
The total number of ancilla (non-velocity, non-grid) qubits required for the quantum circuit to simulate this lattice.
num_total_qubits
The total number of qubits required for the quantum circuit to simulate the lattice. This is the sum of the number of grid, velocity, and ancilla qubits.
registers
A
Tuple[qiskit.QuantumRegister, ...]
that holds registers responsible for specific operations of the QLBM algorithm.circuit
An empty
qiskit.QuantumCircuit
with labeled registers that quantum components use as a base. Each quantum component that is parameterized by aLattice
makes a copy of this quantum circuit to which it appends its designated logic.blocks
A
Dict[str, List[Block]]
that contains all of theBlock
s encoding the solid geometry of the lattice. The key of the dictionary is the specific kind of boundary condition of the obstacle (i.e.,"bounceback"
or"specular"
).logger
The performance logger, by default
getLogger("qlbm")
.A lattice can be constructed from from either an input file or a Python dictionary. A sample configuration might look as follows:
{ "lattice": { "dim": { "x": 16, "y": 16 }, "velocities": { "x": 4, "y": 4 } }, "geometry": [ { "x": [9, 12], "y": [3, 6], "boundary": "specular" }, { "x": [9, 12], "y": [9, 12], "boundary": "bounceback" } ] }
- Parameters:
lattice_data (str | Dict)
logger (Logger)
- parse_input_data(lattice_data)[source]#
Parses the lattice input data, provided in either a file path or a dictionary.
- Parameters:
lattice_data (str | Dict) – Either a file path to read a JSON-formatted specification from, or a dictionary formatted as in the main class description.
- Returns:
A tuple containing (i) a list of the number of gridpoints per dimension, (ii) a list of the number of velicities per dimension, and (iii) a dictionary containing the solid
Block
s. The key of the dictionary is the specific kind of boundary condition of the obstacle (i.e.,"bounceback"
or"specular"
).- Return type:
Tuple[List[int], List[int], Dict[str, List[Block]]]
- Raises:
LatticeException – If the specification violates any algorithmic assumptions.
- to_json()[source]#
Serialize the lattice specification to JSON format.
- Returns:
The JSON representation of the lattice.
- Return type:
str
Components Base#
- class qlbm.components.base.QuantumComponent(logger=<Logger qlbm (WARNING)>)[source]#
Base class for all quantum circuits implementing QLBM functionality.
This class wraps a
qiskit.QuantumCircuit
object constructed through the parameters supplied to the constructor. Thecreate_circuit()
is automatically called at construct time and its output is stored in the circuit attribute. All quantum components have an implementation of thecreate_circuit()
method which builds their specialized quantum circuits.Attribute
Summary
circuit
The
qiskit.QuantumCircuit
of the component.logger
The performance logger, by default
getLogger("qlbm")
- Parameters:
logger (Logger)
- abstract create_circuit()[source]#
Creates the
qiskit.QuantumCircuit
of this object.This method is called automatically at construction time for all quantum components.
- Returns:
The generated QuantumCircuit.
- Return type:
QuantumCircuit
- width()[source]#
Return the number of qubits plus clbits in the circuit.
- Returns:
Width of circuit.
- Return type:
int
- size()[source]#
Returns the total number of instructions (gates) in the circuit.
- Returns:
The total number of gates in the circuit.
- Return type:
int
- dump_qasm3(stream)[source]#
Serialize to QASM3.
- Parameters:
stream (TextIOBase) – The stream to output to.
- Return type:
None
- class qlbm.components.base.LBMPrimitive(logger=<Logger qlbm (WARNING)>)[source]#
Base class for all primitive-level quantum components.
A primitive component is a small, isolated, and structurally parameterizable quantum circuit that can be reused throughout one or multiple algorithms.
Attribute
Summary
circuit
The
qiskit.QuantumCircuit
of the primitive.logger
The performance logger, by default
getLogger("qlbm")
- Parameters:
logger (Logger)
- class qlbm.components.base.LBMOperator(lattice, logger=<Logger qlbm (WARNING)>)[source]#
Base class for all operator-level quantum components.
An operator component implements a specific physical operation corresponding to the classical LBM (streaming, collision, etc.). Operators are inferred based on the structure of a
Lattice
object of an appropriate encoding.Attribute
Summary
circuit
The
qiskit.QuantumCircuit
of the operator.lattice
The
Lattice
based on which the properties of the operator are inferred.logger
The performance logger, by default
getLogger("qlbm")
- Parameters:
lattice (Lattice)
logger (Logger)
- class qlbm.components.base.CQLBMOperator(lattice, logger=<Logger qlbm (WARNING)>)[source]#
Specialization of the
LBMOperator
operator class for the Collisionless Quantum Transport Method algorithm by Schalkers and Möller [2].Specializaitons of this class infer their properties based on a
CollisionlessLattice
.Attribute
Summary
circuit
The
qiskit.QuantumCircuit
of the operator.lattice
The
CollisionlessLattice
based on which the properties of the operator are inferred.logger
The performance logger, by default
getLogger("qlbm")
- Parameters:
lattice (CollisionlessLattice)
logger (Logger)
- class qlbm.components.base.SpaceTimeOperator(lattice, logger=<Logger qlbm (WARNING)>)[source]#
Specialization of the
LBMOperator
operator class for the Space-Time QBM algorithm by Schalkers and Möller [4].Specializaitons of this class infer their properties based on a
SpaceTimeLattice
.Attribute
Summary
circuit
The
qiskit.QuantumCircuit
of the operator.lattice
The
SpaceTimeLattice
based on which the properties of the operator are inferred.logger
The performance logger, by default
getLogger("qlbm")
- Parameters:
lattice (SpaceTimeLattice)
logger (Logger)
- class qlbm.components.base.LBMAlgorithm(lattice, logger=<Logger qlbm (WARNING)>)[source]#
Base class for all end-to-end Quantum Boltzmann Methods.
An end-to-end algorithm consists of a series of
LBMOperator
that perform the physical operations of the appropriate algorithm.Attribute
Summary
circuit
The
qiskit.QuantumCircuit
of the algorithm.lattice
The
Lattice
based on which the properties of the algorithm are inferred.logger
The performance logger, by default
getLogger("qlbm")
- Parameters:
lattice (Lattice)
logger (Logger)