qat.qpus.CLinalg
For a general description of linear-algebra-based simulators, please refer to the PyLinalg documentation page.
High-level Quantum Processing Unit
- class qat.qpus.CLinalg(use_nbthreads_heuristic: bool = True, precision: int = 2, sparse: bool = False, light_circuit: bool = False, tqdm: bool = False, fusion: bool = True, readonly_statevector: bool = False, seed: int = None)
CLinalg simulator
- Parameters
use_nbthreads_heuristic (bool) – use heuristic for choosing the number of threads setting this parameter to False will result in using OMP_NUM_THREADS Default: True
precision (int) – precision used for the simulation, either 1(single) or 2(double) Default: 2
sparse (bool) – whether or not to return a sparse result Default: False
light_circuit (bool) – option still in development Default: False
tqdm (bool) – use tqdm to display progress in simulating the circuit Default: False
fusion (bool) – use the FusionPlugin as a pre-processing step, merging gates together Default: True
readonly_statevector (bool) – the statevector included in the result is returned directly in memory from the C++ array. This statevector will then be in convention lsb first. This option only makes sense for perfect sampling where all qubits are measured. Default: False
seed (int) – seed of the random number generator Default: None (will use a random seed)
- submit(batch: Batch, meta_data: Optional[dict] = None) BatchResult
Executes a batch of jobs and returns the corresponding list of Results.
- Parameters
batch (
Batch
) – a batch of jobs. If a single job is provided, the job is embedded into a Batch, executed, and the first result is returned.- Returns
a batch result
- Return type
This high-level class wrapping the simulator follows the convention
of the qat.qpus.QPUHandler
structure.
C++ Low-level Statevector
Though not the standard or recommended way of using qat.qpus.CLinalg
, the C++ statevector
object underneath this QPU can be accessed throught the statevector parameter, for instance:
from qat.clinalg import CLinalg
qpu = CLinalg()
# change number of qubits to 2
qpu.statevector.resize(2)
# reset the state to |00> and print the state
qpu.statevector.reset()
qpu.statevector.print()
0: (1,0)
1: (0,0)
2: (0,0)
3: (0,0)
Warning
Do consider that the bit convention used in this lower-level statevector is reversed compared to the more intuitive one supported by the QPU interface. Intuitively, you will consider a state \(|i_0i_1i_2i_3\rangle\) (with qubit 0 being the most significant bit); however the ordering used by the low-level statevector instance \(|i_3i_2i_1i_0\rangle\) (with qubit 0 being the least significant bit). This influences the statevector methods print, reset (if a value is provided) and the way in which the statevector is interacted with through the array property.
Pybind interface
- class qat.clinalg.wrapper.StateVectorCPUDouble
- apply_1qbit_ctrl_gate(self: qat.clinalg.wrapper.StateVectorCPUDouble, ctrl_qubits: List[int], qubit: int, matrix: List[complex]) None
Apply a k-controlled 1 qubit gate.
- apply_1qbit_gate(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit: int, matrix: List[complex]) None
Apply a general 1 qubit gate.
- apply_2qbit_ctrl_gate(self: qat.clinalg.wrapper.StateVectorCPUDouble, ctrl_qubits: List[int], qubit1: int, qubit2: int, matrix: List[complex]) None
Apply a k-controlled 2 qubits gate.
- apply_2qbit_gate(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit1: int, qubit2: int, matrix: List[complex]) None
Apply a general 2 qubits gate.
- apply_CCNOT(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit1: int, qubit2: int, qubit3: int) None
Apply the CCNOT gate
- apply_CNOT(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit1: int, qubit2: int) None
Apply the CNOT gate
- apply_CSIGN(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit1: int, qubit2: int) None
Apply the CSIGN gate
- apply_H(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit: int, qbits_c: Optional[List[int]] = None) None
Apply the H gate.
- apply_ISWAP(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit1: int, qubit2: int) None
Apply the ISWAP gate.
- apply_PH(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit: int, angle: float, qbits_c: Optional[List[int]] = None) None
Apply the PH gate.
- apply_RX(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit: int, angle: float, qbits_c: Optional[List[int]] = None) None
Apply the RX gate.
- apply_RY(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit: int, angle: float, qbits_c: Optional[List[int]] = None) None
Apply the RY gate.
- apply_RZ(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit: int, angle: float, qbits_c: Optional[List[int]] = None) None
Apply the RZ gate.
- apply_S(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit: int, qbits_c: Optional[List[int]] = None) None
Apply the S gate.
- apply_SQRTSWAP(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit1: int, qubit2: int) None
Apply the SQRTSWAP gate.
- apply_SWAP(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit1: int, qubit2: int) None
Apply the SWAP gate.
- apply_T(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit: int, qbits_c: Optional[List[int]] = None) None
Apply the T gate.
- apply_X(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit: int, qbits_c: Optional[List[int]] = None) None
Apply the X gate.
- apply_Y(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit: int, qbits_c: Optional[List[int]] = None) None
Apply the Y gate.
- apply_Z(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubit: int, qbits_c: Optional[List[int]] = None) None
Apply the Z gate.
- apply_nqbit_ctrl_gate(self: qat.clinalg.wrapper.StateVectorCPUDouble, ctrl_qubits: List[int], qubits: List[int], matrix: List[complex]) None
Apply a k-controlled n qubits gate.
- apply_nqbit_gate(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubits: List[int], matrix: List[complex]) None
Apply a general n qubits gate.
- property array
View of the statevector’s data (does not yield ownership of the data). Values can be edited.
Warning
Qubit 0 is the least significant bit (rightmost).
- property array_readonly
Readonly view of the statevector’s data (does not yield ownership of the data). Values cannot be edited.
Warning
Qubit 0 is the least significant bit (rightmost).
- expectation_value(self: qat.clinalg.wrapper.StateVectorCPUDouble, wobservable: qat.core.wobservable.WObservableDouble) complex
Compute the expectation value of a WObservable (wrapped observable).
- get_distribution(self: qat.clinalg.wrapper.StateVectorCPUDouble, amp_threshold: float, qubits: List[int]) numpy.ndarray[numpy.float64]
Return the marginal distribution over a subset of qubits, as a numpy array. Probabilities which amplitudes are below amp_threshold are set to 0. The first qubit is the most valuable bit.
- get_mapped_distribution(self: qat.clinalg.wrapper.StateVectorCPUDouble, amp_threshold: float, qubits: List[int]) object
Return a MapIntDouble object, mapping the states of the marginal distribution over a subset of qubits, to their amplitudes. Only amplitudes higher than amp_threshold are mapped (no copy C++ map).
- get_mapped_statevector(self: qat.clinalg.wrapper.StateVectorCPUDouble, amp_threshold: float) Dict[int, complex]
Return a dictionary mapping states which amplitudes are higher than the threshold, to their amplitudes (performs a copy of a C++ map).
- get_permuted_statevector(self: qat.clinalg.wrapper.StateVectorCPUDouble, amp_threshold: float) numpy.ndarray[numpy.complex128]
Return the statevector as a numpy array (performs a copy and a permutation for putting the qubit 0 as most significant). Amplitudes lower than amp_threshold are set to 0.
- measure(self: qat.clinalg.wrapper.StateVectorCPUDouble, qbits: List[int]) int
Return a state from the statevector (does not project, this is done separately using the project method!).
- print(self: qat.clinalg.wrapper.StateVectorCPUDouble) None
Print the statevector to the standard output.
- probability(self: qat.clinalg.wrapper.StateVectorCPUDouble, state: int, qbits: Optional[List[int]] = None) float
Return the probability of a given state.
- project(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubits: List[int], state: int) None
Project a subset of qubits on a given state.
- project_then_reset(self: qat.clinalg.wrapper.StateVectorCPUDouble, qubits: List[int], state: int) None
Reset qubits to 0, after having projected them on a previously measured state
- sample(self: qat.clinalg.wrapper.StateVectorCPUDouble, nbshots: int) object
Return a MapIntInt object, mapping states which have been sampled, to their number of occurences (no copy C++ map).
- sample_subset(self: qat.clinalg.wrapper.StateVectorCPUDouble, nbshots: List[int], qubits: int) object
Return a MapIntInt object, mapping states which have been sampled out of a subset of qubits, to their number of occurences (no copy C++ map).
- set_num_threads(self: qat.clinalg.wrapper.StateVectorCPUDouble, nbthreads: int) None
Set number of threads to be used.
- simulate_circuit(self: qat.clinalg.wrapper.StateVectorCPUDouble, wcircuit: pblinalg::PybindLinAlgWCircuit<double>) None
Simulate a PybindLinAlgWCircuit (lightweight wrapped circuit).