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 | None = None, light_circuit: bool = False, tqdm: bool = False, fusion: bool = True, readonly_statevector: bool = False, individual_terms_values: bool = False, seed: int = None, **kwargs)

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) – deprecated, only works for some named gates 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 (only for at least 23 qubits) 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

  • individual_terms_values (bool) – if True, each observable term exceptation value will be individually filled into value_data and error_data maps. Slight performance decrease. Default: False

  • seed (int) – seed of the random number generator Default: None (will use a random seed)

submit(batch: Batch, meta_data: 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:

(BatchResult)

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.myqlm_clinalg.wrapper.StateVectorCPUDouble
apply_1qbit_ctrl_gate(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, ctrl_qubits: collections.abc.Sequence[SupportsInt], qubit: SupportsInt, matrix: collections.abc.Sequence[complex]) None

Apply a k-controlled 1 qubit gate.

apply_1qbit_gate(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit: SupportsInt, matrix: collections.abc.Sequence[complex]) None

Apply a general 1 qubit gate.

apply_2qbit_ctrl_gate(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, ctrl_qubits: collections.abc.Sequence[SupportsInt], qubit1: SupportsInt, qubit2: SupportsInt, matrix: collections.abc.Sequence[complex]) None

Apply a k-controlled 2 qubits gate.

apply_2qbit_gate(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit1: SupportsInt, qubit2: SupportsInt, matrix: collections.abc.Sequence[complex]) None

Apply a general 2 qubits gate.

apply_CCNOT(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit1: SupportsInt, qubit2: SupportsInt, qubit3: SupportsInt) None

Apply the CCNOT gate

apply_CNOT(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit1: SupportsInt, qubit2: SupportsInt) None

Apply the CNOT gate

apply_CSIGN(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit1: SupportsInt, qubit2: SupportsInt) None

Apply the CSIGN gate

apply_H(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit: SupportsInt, qbits_c: collections.abc.Sequence[SupportsInt] | None = None) None

Apply the H gate.

apply_ISWAP(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit1: SupportsInt, qubit2: SupportsInt) None

Apply the ISWAP gate.

apply_PH(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit: SupportsInt, angle: SupportsFloat, qbits_c: collections.abc.Sequence[SupportsInt] | None = None) None

Apply the PH gate.

apply_RX(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit: SupportsInt, angle: SupportsFloat, qbits_c: collections.abc.Sequence[SupportsInt] | None = None) None

Apply the RX gate.

apply_RY(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit: SupportsInt, angle: SupportsFloat, qbits_c: collections.abc.Sequence[SupportsInt] | None = None) None

Apply the RY gate.

apply_RZ(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit: SupportsInt, angle: SupportsFloat, qbits_c: collections.abc.Sequence[SupportsInt] | None = None) None

Apply the RZ gate.

apply_S(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit: SupportsInt, qbits_c: collections.abc.Sequence[SupportsInt] | None = None) None

Apply the S gate.

apply_SQRTSWAP(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit1: SupportsInt, qubit2: SupportsInt) None

Apply the SQRTSWAP gate.

apply_SWAP(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit1: SupportsInt, qubit2: SupportsInt) None

Apply the SWAP gate.

apply_T(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit: SupportsInt, qbits_c: collections.abc.Sequence[SupportsInt] | None = None) None

Apply the T gate.

apply_X(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit: SupportsInt, qbits_c: collections.abc.Sequence[SupportsInt] | None = None) None

Apply the X gate.

apply_Y(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit: SupportsInt, qbits_c: collections.abc.Sequence[SupportsInt] | None = None) None

Apply the Y gate.

apply_Z(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubit: SupportsInt, qbits_c: collections.abc.Sequence[SupportsInt] | None = None) None

Apply the Z gate.

apply_binary_qram(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, numpy_array: Annotated[numpy.typing.ArrayLike, numpy.uint64], qbits: collections.abc.Sequence[SupportsInt], target_reg_size: SupportsInt) None

Apply a BinaryQRAM oracle

apply_nqbit_ctrl_gate(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, ctrl_qubits: collections.abc.Sequence[SupportsInt], qubits: collections.abc.Sequence[SupportsInt], matrix: collections.abc.Sequence[complex]) None

Apply a k-controlled n qubits gate.

apply_nqbit_gate(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubits: collections.abc.Sequence[SupportsInt], matrix: collections.abc.Sequence[complex]) None

Apply a general n qubits gate.

apply_phase_oracle(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, states: collections.abc.Sequence[SupportsInt], qbits: collections.abc.Sequence[SupportsInt]) None

Apply a PhaseOracle oracle

apply_qram(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, numpy_array: Annotated[numpy.typing.ArrayLike, numpy.complex128], qbits: collections.abc.Sequence[SupportsInt], target_reg_size: SupportsInt) None

Apply a QRAM oracle

apply_state_preparation(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, numpy_array: Annotated[numpy.typing.ArrayLike, numpy.complex128], qbits: collections.abc.Sequence[SupportsInt]) None

Apply a StatePreparation oracle

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).

evaluate_terms(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, terms: collections.abc.Sequence[pblinalg::SimpleTerm<double>], nbshots: typing.SupportsInt) list[tuple[complex, complex]]

Evaluate values for the given terms

expectation_value(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, wobservable: qat.linalgutil.wobservable.WObservableDouble) complex

Compute the expectation value of a WObservable (wrapped observable).

get_distribution(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, amp_threshold: SupportsFloat, qubits: collections.abc.Sequence[SupportsInt]) numpy.typing.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_density_diag(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, amp_threshold: SupportsFloat) dict[int, float]

Return a dictionary mapping states which probabilities are higher than the threshold, to their probabilities (performs a copy of a C++ map).

get_mapped_distribution(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, amp_threshold: SupportsFloat, qubits: collections.abc.Sequence[SupportsInt]) object

Return a MapIntDouble/MapIntFloat 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.myqlm_clinalg.wrapper.StateVectorCPUDouble, amp_threshold: SupportsFloat) 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_density_diag(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, amp_threshold: SupportsFloat) numpy.typing.NDArray[numpy.float64]

Return the density matrix diagonal as a numpy array (performs a copy and a permutation for putting the qubit 0 as most significant). Probabilities lower than squared amp_threshold are set to 0.

get_permuted_density_matrix(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, amp_threshold: SupportsFloat) numpy.typing.NDArray[numpy.complex128]
get_permuted_statevector(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, amp_threshold: SupportsFloat) numpy.typing.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.

make_reservation(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble) None
measure(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qbits: collections.abc.Sequence[SupportsInt]) int

Return a state from the statevector (does not project, this is done separately using the project method!).

print(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble) None

Print the statevector to the standard output.

probability(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, state: SupportsInt, qbits: collections.abc.Sequence[SupportsInt] | None = None) float

Return the probability of a given state.

project(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubits: collections.abc.Sequence[SupportsInt], state: SupportsInt) None

Project a subset of qubits on a given state.

project_then_reset(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, qubits: collections.abc.Sequence[SupportsInt], state: SupportsInt) None

Reset qubits to 0, after having projected them on a previously measured state

release_reservation(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble) None
reset_to_str(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, psi_0_str: str) None

Reset the circuit to a specific state

sample(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, nbshots: SupportsInt) numpy.typing.NDArray[numpy.uint64]

Return a numpy array of sampled states

sample_subset(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, nbshots: collections.abc.Sequence[SupportsInt], qubits: SupportsInt) numpy.typing.NDArray[numpy.uint64]

Return a numpy array of states sampled over a subset of qubits

set_num_threads(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, nbthreads: SupportsInt) None

Set number of threads to be used.

simulate_circuit(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, wcircuit: pblinalg::PybindLinAlgWCircuit<double>) None

Simulate a PybindLinAlgWCircuit (lightweight wrapped circuit).

terms_expectations_values(self: qat.myqlm_clinalg.wrapper.StateVectorCPUDouble, wobservable: qat.linalgutil.wobservable.WObservableDouble) list[complex]

Compute the expectation values of the terms of a WObservable (wrapped observable).