Simulators

We refer to the demo for a usage sample of the simulator. The simulator has three attributes. While the gates attribute implicitely specifies the pulse shape, the CircuitClass knows how to perform the matrix-vector multiplication seen in the statevector simulation. Last, the parallel attribute specifies whether or not the shots should be executed in parallel with multiprocessing. In general, we recommend to parallelize the outer loop of the simulation, and not the shots, as the latter comes with a large overhead.

class quantum_gates.simulators.MrAndersonSimulator(gates: ~quantum_gates._gates.gates.Gates = <quantum_gates._gates.gates.Gates object>, CircuitClass=<class 'quantum_gates._simulation.circuit.Circuit'>, parallel: bool = False)[source]

Bases: object

Simulates a noisy quantum circuit, extracting the gate instructions from a transpiled qiskit QuantumCircuit.

Note that the shots can be parallelized, but this comes with a large overhead. Thus, we recommend to parallelize the usage of the simulator instead. This can be done with the function src.utility.simulation_utility.perform_parallel_simulation.

Parameters:
  • gates (Union[Gates, ScaledNoiseGates, NoiseFreeGates]) – Gateset to be used, contains the pulse information.

  • CircuitClass (Union[Circuit, EfficientCircuit]) – Performs the computations with the backend.

  • parallel (bool) – Whether or not the shots should be run in parallel. False by default.

Note

At the moment, we only support a linear topology.

Example

from quantum_gates.simulators import MrAndersonSimulator
from quantum_gates.gates import standard_gates
from quantum_gates.circuits import EfficientCircuit

sim = MrAndersonSimulator(
    gates==standard_gates,
    CircuitClass=EfficientCircuit,
    parallel=False
)

sim.run(t_qiskit_circ=...,
        qubits_layout=...,
        psi0=np.array([1.0, 0.0, 0.0, 0.0]),
        shots=1000,
        device_param=...,
        nqubit=2)
gates[source]

Gateset to be used, contains the pulse information.

Type:

Union[Gates, ScaledNoiseGates, NoiseFreeGates]

CircuitClass[source]

Performs the computations with the backend.

Type:

Union[Circuit, EfficientCircuit]

parallel[source]

Whether or not the shots should be run in parallel. False by default.

Type:

bool

run(t_qiskit_circ, qubits_layout: list, psi0: array, shots: int, device_param: dict, nqubit: int)[source]

Takes as input a transpiled qiskit circuit on a given backend with a given qubits layout and runs noisy quantum gates. Warning: Qubits layout must have a linear topology. :param t_qiskit_circ: transpiled qiskit circuit (QuantumCircuit) :param qubits_layout: qubits layout with linear topology (list) :param psi0: initial state (array) :param shots: number of realizations (int) :param device_param: noise and device configurations as dict with the keys specified by DeviceParameters (dict) :param nqubit: number of qubits used in the circuit, must be compatible with psi0 (int)

Returns:

vector of probabilities (array)

Parameters:
  • qubits_layout (list) –

  • psi0 (array) –

  • shots (int) –

  • device_param (dict) –

  • nqubit (int) –

_validate_input_of_run(t_qiskit_circ, qubits_layout, psi0, shots, device_param, nqubit)[source]

Performs sanity checks on the input of the run() method. Raises an Exception if any mistakes are found.

_preprocess_circuit(t_qiskit_circ, qubits_layout: list, nqubit: int) tuple[source]

Preprocess of QuantumCircuit.data. We count the number of RZ gates (n_rz), keep track of the swaps (swap_detector), and bring the circuit in a format (data) that is compatible with the rest of the simulation.

Parameters:
  • qubits_layout (list) –

  • nqubit (int) –

Return type:

tuple

_perform_simulation(shots: int, data: list, n_rz: int, nqubit: int, device_param: dict, psi0: array) array[source]

Performs the simulation shots many times and returns the resulting probability distribution.

Parameters:
  • shots (int) –

  • data (list) –

  • n_rz (int) –

  • nqubit (int) –

  • device_param (dict) –

  • psi0 (array) –

Return type:

array

_fix_probabilities(wrong_probs: array, qubits_order: list, nqubit: int)[source]

This function fix the final probabilities in the right way (in case of swaps in the circuit)

Parameters:
  • wrong_probs (array) –

  • qubits_order (list) –

  • nqubit (int) –

class quantum_gates.simulators.LegacyMrAndersonSimulator[source]

Bases: object

Simulates a quantum circuit with the Noisy quantum gates approach.

Note

This version is only meant for unit testing and the documentation

run(qiskit_circ, backend, qubits_layout: list, psi0: array, shots: int, device_param: DeviceParameters)[source]

Performs a run of the simulator.

Takes as input a qiskit circuit on a given backend with a given qubits layout and runs noisy quantum gates.

Note

This simulator has a slightly different interface than the newer MrAndersonSimulator. Moreover, the qubits layout must have a linear topology.

Parameters:
  • qiskit_circ – qiskit circuit (QuantumCircuit)

  • backend – IMBQ backend (backend)

  • qubits_layout (list) – qubits layout with linear topology (list)

  • psi0 (array) – initial state (array)

  • shots (int) – number of realizations (int)

  • device_param (DeviceParameters) – object that contains the measured noise (DeviceParameters)

Example

from quantum_gates.simulators import LegacyMrAndersonSimulator

sim = LegacyMrAndersonSimulator()
sim.run(qiskit_circ,
        backend,
        qubits_layout,
        psi0,
        shots,
        device_param)
Returns:

Vector of probabilities and density matrix

Parameters:
fix_probs(wrong_probs: array, qubits_order: list, nqubit: int)[source]

This function fix the final probabilities in the right way (in case of swaps in the circuit)

Parameters:
  • wrong_probs (array) –

  • qubits_order (list) –

  • nqubit (int) –