Backends¶
Choose a backend to run circuits over Forge using statevector simulation or measurementbased computing. Refer to these Jupyter Notebook tutorials on Forge:
GettingStarted/Examples/Circuits/start_here.ipynb
GettingStarted/Examples/Circuits/quasar_measurement.ipynb
Classes
QuasarSimulatorBackend
QiskitHardwareBackend
QiskitSimulatorBackend
CirqSimulatorBackend
Class Backend
Class QuasarSimulatorBackend

Class QiskitHardwareBackend



Class QiskitSimulatorBackend



Class CirqSimulatorBackend



Module Measurement
Backend¶

class
quasar.backend.
Backend
¶ Class Backend represents a physical or simulated quantum circuit resource. Backends must implement run_measurement, from which many higherorder quantities may be computed, e.g., run_pauli_expectation, run_pauli_expectation_value, run_pauli_expectation_value_gradient, etc. Backends supporting classical statevectorbased simulation may also optionally implement run_statevector, from which many additional higherorder quantities may be computed, e.g., run_unitary, run_density_matrix, and idealinfinitesampled versions of the previouslydiscussed higherorder quantities. Backends may additionally overload any of the stock higherorder methods declared here, potentially providing increased performance or additional methodology.

property
has_run_statevector
¶ Does this Backend support run_statevector?
Backend subclasses should OVERLOAD this method.
 Returns
True if run_statevector is supported else False.
 Return type
bool

property
has_statevector_input
¶ Does this Backend allow statevector to be passed as input argument to various run methods?
Backend subclasses should OVERLOAD this method.
 Returns
True if statevector input arguments can be supplied else False.
 Return type
bool

run_measurement
(circuit, nmeasurement=None, statevector=None, min_qubit=None, nqubit=None, dtype=<class 'numpy.complex128'>, **kwargs)¶ Run a circuit using measurementbased computing.
 Parameters
circuit (Circuit) – the circuit to run
nmeasurement (int or None) – number of measurements to sample. If None, infinite sampling is assumed and the probabilities are directly returned in ProbabilityHistogram format (default  None)
statevector (
np.ndarray
, shape 2**N) – input statevector (default  None)min_qubit (int) – the minimum occupied qubit index (default  None)
nqubit (int) – number of qubits (default  None)
dtype (real or complex dtype) – the dtype to perform the computation at. The gate operator will be cast to this dtype. Note that using real dtypes (float64 or float32) can reduce storage and runtime, but the imaginary parts of the input wfn and all gate unitary operators will be discarded without checking. In these cases, the user is responsible for ensuring that the circuit works on O(2^N) rather than U(2^N) and that the output is valid. (default  np.complex128)
 Returns
histogram of projective measurements taken while running the circuit
 Return type

run_measurements
(circuits, nmeasurement=None)¶ Run a sequence of circuits using measurementbased computing.
Returns a sequence of ProbabilityHistogram objects.
As the circuits could be very different, statevector input or min_qubit/nqubit are not supported. The default behaviour is to simply run the circuits in sequence, but on some hardware backends a speed advantage can be gained by batching circuits into jobs.
 Parameters
circuits (Sequence[Circuit]) – the circuits to run
nmeasurement (int or Sequence[int] or None) – number of measurements to sample. If None, infinite sampling is assumed and the probabilities are directly returned in ProbabilityHistogram format (default  None) If an int, that number of measurements will be used for all circuits. If a sequence, run_measurements returns the shortest of len(circuits) and len(nmeasurement).
 Returns
list of histograms of projective measurements taken while running the circuits
 Return type
list[ProbabilityHistogram]

run_pauli_expectation_value
(circuit, pauli, nmeasurement=None, statevector=None, min_qubit=None, nqubit=None, dtype=<class 'numpy.complex128'>, **kwargs)¶ Compute the total observable expectation value of a Paulisparse Hermitian operator using the statevector generated by the circuit at the current parameter set.
 Parameters
circuit (Circuit) – the circuit for which to calculate the expectation value.
pauli (Pauli) – the Hermitian operator supplied in sparse Pauli form.
nmeasurement (int) – number of measurements to sample. If default value None, assume infinite sampling.
statevector (
np.ndarray
of shape 2**N, complex dtype) – the statevector generated by the circuit. If default value None, all qubits in the statevector set equal to 0.min_qubit (int) – the minimum occupied qubit index (default  None).
nqubit (int) – the total number of qubit indices in the circuit, including empty qubit indices (default  None).
dtype (complex dtype) – the dtype to perform the computation at. (default 
np.complex128
).
 Returns
total observable expectation value
 Return type
float, complex dtype

run_pauli_expectation_value_gradient
(circuit, pauli, nmeasurement=None, statevector=None, min_qubit=None, nqubit=None, dtype=<class 'numpy.complex128'>, parameter_indices=None, **kwargs)¶ Compute the gradient, with respect to a circuit’s current parameter set, of the total observable expectation value of a Paulisparse Hermitianoperatorusing the statevector generated by the circuit at the current parameter set.
 Parameters
circuit (Circuit) – the circuit for which to calculate the expectation value.
pauli (Pauli) – the Hermitian operator supplied in sparse Pauli form.
nmeasurement (int) – number of measurements to sample. If default value None, assume infinite sampling.
statevector (
np.ndarray
of shape 2**N, complex dtype) – the statevector generated by the circuit. If default value None, all qubits in the statevector set equal to 0.min_qubit (int) – the minimum occupied qubit index (default  None).
nqubit (int) – the total number of qubit indices in the circuit, including empty qubit indices (default  None).
dtype (complex dtype) – the dtype to perform the computation at. (default 
np.complex128
).parameter_indices (list of ints) – take the gradient with respect to these parameter indices. If default value None, take the gradient with respect to all parameters.
 Returns
np.ndarray
with shape equal to parameter_indices, complex dtype: gradient of total observable expectation value with respect to the circuit’s current parameter set.

run_statevector
(circuit, statevector=None, min_qubit=None, nqubit=None, dtype=<class 'numpy.complex128'>, **kwargs)¶ Run a circuit using statevector simulation.
Backend subclasses should OVERLOAD this method.
 Parameters
circuit (Circuit) – the circuit to run
statevector (
np.ndarray
, shape 2**N) – input statevector (default  None)min_qubit (int) – the minimum occupied qubit index (default  None)
nqubit (int) – number of qubits (default  None)
dtype (real or complex dtype) – the dtype to perform the computation at. The gate operator will be cast to this dtype. Note that using real dtypes (float64 or float32) can reduce storage and runtime, but the imaginary parts of the input wfn and all gate unitary operators will be discarded without checking. In these cases, the user is responsible for ensuring that the circuit works on O(2^N) rather than U(2^N) and that the output is valid. (default  np.complex128)
 Returns
full output statevector
 Return type
np.ndarray
, shape 2**N

property
summary_str
¶ A moreextensive string representation of this Backend, optionally including current hardware state.
Backend subclasses should OVERLOAD this method.
 Returns
multiline string representation of this Backend
 Return type
str

property
QuasarBackend¶

class
quasar.quasar_backend.
QuasarSimulatorBackend
¶ 
property
has_run_statevector
¶ Does this Backend support run_statevector?
Backend subclasses should OVERLOAD this method.
 Returns
True if run_statevector is supported else False.
 Return type
bool

property
has_statevector_input
¶ Does this Backend allow statevector to be passed as input argument to various run methods?
Backend subclasses should OVERLOAD this method.
 Returns
True if statevector input arguments can be supplied else False.
 Return type
bool

run_statevector
(circuit, statevector=None, min_qubit=None, nqubit=None, dtype=<class 'numpy.complex128'>)¶ Run a circuit using statevector simulation.
Backend subclasses should OVERLOAD this method.
 Parameters
circuit (Circuit) – the circuit to run
statevector (
np.ndarray
, shape 2**N) – input statevector (default  None)min_qubit (int) – the minimum occupied qubit index (default  None)
nqubit (int) – number of qubits (default  None)
dtype (real or complex dtype) – the dtype to perform the computation at. The gate operator will be cast to this dtype. Note that using real dtypes (float64 or float32) can reduce storage and runtime, but the imaginary parts of the input wfn and all gate unitary operators will be discarded without checking. In these cases, the user is responsible for ensuring that the circuit works on O(2^N) rather than U(2^N) and that the output is valid. (default  np.complex128)
 Returns
full output statevector
 Return type
np.ndarray
, shape 2**N

property
summary_str
¶ A moreextensive string representation of this Backend, optionally including current hardware state.
Backend subclasses should OVERLOAD this method.
 Returns
multiline string representation of this Backend
 Return type
str

property
QiskitBackend¶
CirqBackend¶
Measurement¶

class
quasar.measurement.
CountHistogram
(nqubit, histogram={}, nmeasurement=None)¶ Class CountHistogram represents the output of thhe measurement process for a Circuit. A CountHistogram object contains the number of qubits measured (
nqubit
attribute), the total number of measurements made (nmeasurement
attribute), and a histogram of binary strings representing the collective measurement result (Ket
strings) together with the integral number of times that each one was observed.To access the probability corresponding to a specific
Ket
string, index into the CountHistogram instance with the integer equivalent of the binaryKet
string or the binary string itself.
to_probability_histogram
()¶ Convert from a CountHistogram to a ProbabilityHistogram.


class
quasar.measurement.
ProbabilityHistogram
(nqubit, histogram={}, nmeasurement=None)¶ Class ProbabilityHistogram represents the output of the measurement process for a Circuit. A ProbabilityHistogram object contains the number of qubits measured (
nqubit
attribute), the total number of measurements made (nmeasurement
attribute), and a histogram of binary strings representing each collective measurement result (Ket
strings) together with the probability that each one was observed.To access the probability corresponding to a specific
Ket
string, index into the ProbabilityHistogram instance with the integer equivalent of the binaryKet
string or the binary string itself.
to_count_histogram
()¶ Convert from a ProbabilityHistogram to a CountHistogram.
