Interface
- class slowquant.qiskit_interface.interface.QuantumInterface(primitive: BaseEstimatorV1 | BaseSamplerV1, ansatz: str, mapper: FermionicMapper, ansatz_options: dict[str, Any] = {}, shots: None | int = None, max_shots_per_run: int = 100000, do_M_mitigation: bool = False, do_M_iqa: bool = False, do_M_ansatz0: bool = False)
Quantum interface class.
This class handles the interface with qiskit and the communication with quantum hardware.
Interface to Qiskit to use IBM quantum hardware or simulator.
- Parameters:
primitive – Qiskit Estimator or Sampler object.
ansatz – Name of ansatz to be used.
mapper – Qiskit mapper object, e.g. JW or Parity.
ansatz_options – Ansatz options.
mapper – Qiskit mapper object.
shots – Number of shots. If not specified use shotnumber from primitive (default).
max_shots_per_run – Maximum number of shots allowed in a single run. Set to 100000 per IBM machines.
do_M_mitigation – Do error mitigation via read-out correlation matrix.
do_M_iqa – Use independent qubit approximation when constructing the read-out correlation matrix.
do_M_ansatz0 – Use the ansatz with theta=0 when constructing the read-out correlation matrix
- _estimator_quantum_expectation_value(op: FermionicOperator, run_parameters: list[float]) float
Calculate expectation value of circuit and observables via Estimator.
- Parameters:
op – SlowQuant fermionic operator.
run_parameters – Circuit parameters.
- Returns:
Expectation value of operator.
- _make_Minv() None
Make inverse of read-out correlation matrix with one device call.
The read-out correlation matrix is of the form (for two qubits):
\[\begin{split}M = \begin{pmatrix} P(00|00) & P(00|10) & P(00|01) & P(00|11)\\ P(10|00) & P(10|10) & P(10|01) & P(10|11)\\ P(01|00) & P(01|10) & P(01|01) & P(01|11)\\ P(11|00) & P(11|10) & P(11|01) & P(11|11) \end{pmatrix}\end{split}\]With \(P(AB|CD)\) meaning the probability of reading \(AB\) given the circuit is prepared to give \(CD\).
The construction also supports the independent qubit approximation, which for two qubits means that:
\[P(\tilde{q}_1 \tilde{q}_0|q_1 q_0) = P(\tilde{q}_1|q_1)P(\tilde{q}_0|q_0)\]Under this approximation only \(\left<00\right|\) and \(\left<11\right|\) need to be measured, in order the gain enough information to construct \(M\).
The read-out correlation take the following form (for two qubits):
\[\begin{split}M = \begin{pmatrix} P_{q1}(0|0)P_{q0}(0|0) & P_{q1}(0|1)P_{q0}(0|0) & P_{q1}(0|0)P_{q0}(0|1) & P_{q1}(0|1)P_{q0}(0|1)\\ P_{q1}(1|0)P_{q0}(0|0) & P_{q1}(1|1)P_{q0}(0|0) & P_{q1}(1|0)P_{q0}(0|1) & P_{q1}(1|1)P_{q0}(0|1)\\ P_{q1}(0|0)P_{q0}(1|0) & P_{q1}(0|1)P_{q0}(1|0) & P_{q1}(0|0)P_{q0}(1|1) & P_{q1}(0|1)P_{q0}(1|1)\\ P_{q1}(1|0)P_{q0}(1|0) & P_{q1}(1|1)P_{q0}(1|0) & P_{q1}(1|0)P_{q0}(1|1) & P_{q1}(1|1)P_{q0}(1|1) \end{pmatrix}\end{split}\]The construct also support the building of the read-out correlation matrix when the ansatz is included:
\[\left<00\right| \rightarrow \left<00\right|\boldsymbol{U}^\dagger\left(\boldsymbol{\theta}=\boldsymbol{0}\right)\]This way some of the gate-error can be build into the read-out correlation matrix.
- _one_call_sampler_distributions(paulis: PauliList | Pauli, run_parameters: list[list[float]] | list[float], circuits_in: list[QuantumCircuit] | QuantumCircuit) list[dict[str, float]]
Get results from a sampler distribution for several Pauli strings measured on several circuits.
The expectation value of a Pauli string is calcuated as:
\[E = \sum_i^N p_i\left<b_i\left|P\right|b_i\right>\]With \(p_i\) being the \(i\) th probability and \(b_i\) being the i th bit-string.
- Parameters:
paulis – (List of) Pauli strings to measure.
run_paramters – List of parameters of each circuit.
circuits_in – List of circuits
- Returns:
Array of quasi-distributions in order of all circuits results for a given Pauli String first. E.g.: [PauliString[0] for Circuit[0], PauliString[0] for Circuit[1], …]
- _sampler_distribution_p1(pauli: Pauli, run_parameters: list[float], custom_circ: None | QuantumCircuit = None) float
Sample the probability of measuring one for a given Pauli string.
pauli: Pauli string. run_paramters: Ansatz parameters. custom_circ: Custom circuit to run.
- Returns:
p1 probability.
- _sampler_distributions(pauli: PauliList, run_parameters: list[float], custom_circ: None | QuantumCircuit = None) dict[str, float]
Get results from a sampler distribution for one given Pauli string.
The expectation value of a Pauli string is calcuated as:
\[E = \sum_i^N p_i\left<b_i\left|P\right|b_i\right>\]With \(p_i\) being the \(i\) th probability and \(b_i\) being the i th bit-string.
- Parameters:
pauli – Pauli string to measure.
run_paramters – Parameters of circuit.
custom_circ – Specific circuit to run.
- Returns:
Quasi-distributions.
- _sampler_quantum_expectation_value(op: FermionicOperator) float
Calculate expectation value of circuit and observables via Sampler.
Calculated Pauli expectation values will be saved in memory.
The expectation value over a fermionic operator is calcuated as:
\[E = \sum_i^N c_i\left<0\left|P_i\right|0\right>\]With \(c_i\) being the \(i\) the coefficient and \(P_i\) the \(i\) the Pauli string.
- Parameters:
op – SlowQuant fermionic operator.
- Returns:
Expectation value of operator.
- _sampler_quantum_expectation_value_nosave(op: FermionicOperator, run_parameters: list[float]) float
Calculate expectation value of circuit and observables via Sampler.
Calling this function will not use any pre-calculated Pauli expectaion values. Nor will it save any of the calculated Pauli expectation values.
The expectation value over a fermionic operator is calcuated as:
\[E = \sum_i^N c_i\left<0\left|P_i\right|0\right>\]With \(c_i\) being the \(i\) the coefficient and \(P_i\) the \(i\) the Pauli string.
- Parameters:
op – SlowQuant fermionic operator.
run_parameters – Circuit parameters.
- Returns:
Expectation value of operator.
- construct_circuit(num_orbs: int, num_elec: tuple[int, int]) None
Construct qiskit circuit.
- Parameters:
num_orbs – Number of orbitals in spatial basis.
num_elec – Number of electrons (alpha, beta).
- property max_shots_per_run: int
Get max number of shots per run.
- Returns:
Max number of shots pers run.
- op_to_qbit(op: FermionicOperator) SparsePauliOp
Fermionic operator to qbit rep.
- Parameters:
op – Operator as SlowQuant’s FermionicOperator object
- Returns:
Qubit representation of operator.
- property parameters: list[float]
Get ansatz parameters.
- Returns:
Ansatz parameters.
- quantum_expectation_value(op: FermionicOperator, custom_parameters: list[float] | None = None) float
Calculate expectation value of circuit and observables.
- Parameters:
op – Operator as SlowQuant’s FermionicOperator object.
custom_parameters – optional custom circuit parameters.
- Returns:
Expectation value of fermionic operator.
- quantum_variance(op: FermionicOperator, do_cliques: bool = True, no_coeffs: bool = False, custom_parameters: list[float] | None = None) float
Calculate variance (std**2) of expectation value of circuit and observables.
- Parameters:
op – SlowQuant fermionic operator.
do_cliques – boolean if cliques are used.
no_coeffs – boolean if coefficients of each Pauli string are used or all st to 1.
custom_parameters – optional custom circuit parameters.
- Returns:
Variance of expectation value.
- property shots: int | None
Get number of shots.
- Returns:
Number of shots.