To start out with, we have to set up Qiskit instruments
%pip set up qiskit qiskit_ibm_runtime
%pip set up 'qiskit[visualization]'
import qiskit
import qiskit_ibm_runtimeprint(qiskit.model.get_version_info())
print(qiskit_ibm_runtime.model.get_version_info())
1.3.1
0.34.0
Quantum computations consist in constructing quantum circuits, working them on quantum {hardware} and amassing the measured outputs.
To construct a quantum circuit, we begin by specifying a quantity n of qubits for our circuits, the place n could be as massive as 127 or 156, relying on the underling QPU occasion (see processor varieties). All n qubits are initialised within the |0⟩ state, so the preliminary state is |0 ⟩ⁿ . Right here is how we initialise a circuit with 3 qubits in Qiskit.
from qiskit.circuit import QuantumCircuit# A quantum circuit with three qubits
qc = QuantumCircuit(3)
qc.draw('mpl')
Subsequent we are able to add operations on these qubits, within the type of quantum gates, that are unitary operations appearing usually on one or two qubits. As an illustration allow us to add one Hadamard gate appearing on the primary qubit and two CX (aka CNOT) gates on the pairs of qubits (0, 1) and (0, 2).
# Hadamard gate on qubit 0.
qc.h(0)
# CX gates on qubits (0, 1) and (0, 2).
qc.cx(0, 1)
qc.cx(0, 2)qc.draw('mpl')
We get hold of a 3-qubit circuit getting ready the state
To measure the output qubits of the circuit, we add a measurement layer
qc.measure_all()
qc.draw('mpl')
It’s potential to run the circuit and to get its output measured bits as a simulation with StatevectorSampler
or on actual quantum {hardware} with SamplerV2
. Allow us to see the output of a simulation first.
from qiskit.primitives import StatevectorSampler
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit.visualization import plot_distributionsampler = StatevectorSampler()
pm = generate_preset_pass_manager(optimization_level=1)
# Generate the ISA circuit
qc_isa = pm.run(qc)
# Run the simulator 10_000 occasions
num_shots = 10_000
end result = sampler.run([qc_isa], photographs=num_shots).end result()[0]
# Acquire and plot measurements
measurements= end result.knowledge.meas.get_counts()
plot_distribution(measurements)
The measured bits are both (0,0,0) or (1,1,1), with approximate chance near 0.5. That is exactly what we count on from sampling the 3-qubit state ready by the circuit.
We now run the circuit on a QPU (see directions on establishing an IBM Quantum account and retrieving your private token)
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import SamplerV2 as Samplerservice = QiskitRuntimeService(
channel="ibm_quantum",
token=<YOUR_TOKEN>, # use your IBM Quantum token right here.
)
# Fetch a QPU to make use of
backend = service.least_busy(operational=True, simulator=False)
print(f"QPU: {backend.identify}")
goal = backend.goal
sampler = Sampler(mode=backend)
pm = generate_preset_pass_manager(goal=goal, optimization_level=1)
# Generate the ISA circuit
qc_isa = pm.run(qc)
# Run the simulator 10_000 occasions
num_shots = 10_000
end result = sampler.run([qc_isa], photographs=num_shots).end result()[0]
# Acquire and plot measurements
measurements= end result.knowledge.meas.get_counts()
plot_distribution(measurements)
QPU: ibm_brisbane
The measured bits are much like these of the simulation, however now we see just a few occurrences of the bit triplets (0,0,1), (0,1,0), (1,0,0), (0,1,1), (1,0,1) and (1,1,0). These measurements mustn’t happen from sampling the 3-qubit state ready by the chosen circuit. They correspond to quantum errors occurring whereas working the circuit on the QPU.
We wish to quantify the error charge in some way, however it isn’t apparent find out how to do it. In quantum computations, what we actually care about is that the qubit quantum state ready by the circuit is the right state. The measurements that are not (0,0,0) or (1,1,1) point out errors within the state preparation, however this isn’t all. The measurements (0,0,0) and (1,1,1) may be the results of incorrectly ready states, e.g. the state (|0,0,0⟩ + |0,0,1⟩)/√2 can produce the output (0,0,0). Truly, it appears very probably that just a few of the “appropriate” measurements come from incorrect 3-qubit states.
To know this “noise” within the state preparation we’d like the formalism of density matrices to signify quantum states.
The state of an n-qubit circuit with incomplete info is represented by a 2ⁿ× 2ⁿ constructive semi-definite hermitian matrix with hint equal to 1, referred to as the density matrix ρ. Every diagonal aspect corresponds to the chance pᵢ of measuring one of many 2ⁿ potential states in a projective measurement, pᵢ = ⟨ψᵢ| ρ |ψᵢ⟩. The off-diagonal parts in ρ do not likely have a bodily interpretation, they are often set to zero by a change of foundation states. Within the computational foundation, i.e. the usual foundation |bit₀, bit₁, …, bitₙ⟩, they encode the entanglement properties of the state. Vector states |ψ⟩ describing the potential quantum states of the qubits have density matrices ρ = |ψ⟩⟨ψ|, whose eigenvalues are all 0, aside from one eigenvalue, which is the same as 1. They’re referred to as pure states. Generic density matrices signify probabilistic quantum states of the circuit and have eigenvalues between 0 and 1. They’re referred to as blended states. To present an instance, a circuit which is in a state |ψ₁⟩ with chance q and in a state |ψ₂⟩ with chance 1-q is represented by the density matrix ρ = q|ψ₁⟩⟨ψ₁| + (1-q)|ψ₂⟩⟨ψ₂|.
In actual quantum {hardware}, qubits are topic to all types of small unknown interactions with the atmosphere, resulting in a “lack of info”. That is the supply of an incoherent quantum noise. Due to this fact, when making use of gates to qubits and even when getting ready the preliminary state, the quantum state of qubits can’t be described by a pure state, however results in a blended state, which we should describe with a density matrix ρ. Density matrices present a handy strategy to describe quantum circuits in isolation, abstracting the advanced and unknown interactions with the atmosphere.
To study extra about density matrix illustration of quantum states, you possibly can have a look at any quantum info course. The superb Qiskit lecture on this matter is on the market on YouTube.
For a single qubit, the density matrix, within the computational foundation (i.e. the idea 0⟩, ), is a 2×2 matrix
with p₀ = ⟨0|ρ|0⟩ the chance to measure 0, p₁ = 1 — p₀ = ⟨1|ρ|1⟩ the chance to measure 1, and c is a fancy quantity bounded by |c|² ≤ p₀p₁. Pure states have eigenvalues 0 and 1, so their determinant is zero, they usually saturate the inequality with |c|² = p₀p₁.
Within the following, we are going to think about quantum circuits with just a few qubits and we shall be enthusiastic about quantifying how shut the output state density matrix ρ is from the anticipated (theoretical) output density matrix ρ₀. For a single qubit state, we may take into consideration evaluating the values of p₀, p₁ and c, supplied we’re capable of measure them, however in a circuit with extra qubits and a bigger matrix ρ, we wish to provide you with a single quantity quantifying how shut ρ and ρ₀ are. Quantum info idea possesses such amount. It’s referred to as state constancy and it’s outlined by the marginally mysterious formulation
The state constancy F is an actual quantity between 0 an 1, 0 ≤ F ≤ 1, with F = 1 equivalent to having equivalent states ρ = ρ₀ , and F = 0 equivalent to ρ and ρ₀ having orthogonal pictures. Though it isn’t so apparent from the definition, it’s a symmetric amount, F(ρ,ρ₀) = F(ρ₀,ρ).
In quantum circuit computations, the anticipated output state ρ₀ is at all times a pure state ρ₀ = |ψ₀⟩⟨ψ₀| and, on this case, the state constancy reduces to the less complicated formulation
which has the specified interpretation because the chance for the state ρ to be measured within the state |ψ₀⟩ (in a hypothetical experiment implementing a projective measurement onto the state |ψ₀⟩ ).
Within the noise-free case, the produced density matrix is ρ = ρ₀ = |ψ₀⟩⟨ψ₀| and the state constancy is 1. Within the presence of noise the constancy decreases, F < 1.
Within the the rest of this dialogue, our aim shall be to measure the state constancy F of easy quantum circuit in Qiskit, or, extra exactly, to estimate a decrease certain F̃ < F.
To run quantum circuits on QPUs and acquire measurement outcomes, we outline the perform run_circuit
.
def run_circuit(
qc: QuantumCircuit,
service: QiskitRuntimeService = service,
num_shots: int = 100,
) -> tuple[dict[str, int], QuantumCircuit]:
"""Runs the circuit on backend 'num_shots' occasions. Returns the counts of
measurements and the ISA circuit."""
# Fetch an obtainable QPU
backend = service.least_busy(operational=True, simulator=False)
goal = backend.goal
pm = generate_preset_pass_manager(goal=goal, optimization_level=1)# Add qubit mesurement layer and compute ISA circuit
qc_meas = qc.measure_all(inplace=False)
qc_isa = pm.run(qc_meas)
# Run the ISA circuit and acquire outcomes
sampler = Sampler(mode=backend)
end result = sampler.run([qc_isa], photographs=num_shots).end result()
dist = end result[0].knowledge.meas.get_counts()
return dist, qc_isa
The ISA (Instruction Set Structure) circuit qc_isa
returned by this perform is basically a rewriting of the supplied circuit when it comes to the bodily gates obtainable on the QPU, referred to as foundation gates. That is the circuit that’s truly constructed and run on the {hardware}.
Word: The run_circuit
perform begins by fetching an obtainable QPU. That is handy to keep away from ready too lengthy for the computation to be processed. Nonetheless this additionally signifies that we use completely different QPUs every time we name the perform. This isn’t ultimate, as it’s potential that completely different QPUs have completely different stage of quantum noise. Nonetheless, in apply, the fetched QPUs all turned out to be within the Eagle household and we current noise estimation just for this QPU household. To maintain our evaluation easy, we simply assume that the extent of quantum noise among the many potential QPU situations is steady. The reader may attempt to discover whether or not there are variations between situations.
Naked |0⟩ state
Allow us to begin with the best circuit, which includes solely an initialised qubit |0⟩ with none gate operation.
# A quantum circuit with a single qubit |0>
qc = QuantumCircuit(1)
dist, qc_isa = run_circuit(qc, num_shots=100_000)
qc_isa.draw(output="mpl", idle_wires=False, model="iqp")
import numpy as npdef print_results(dist: dict[str, int]) -> None:
print(f"Measurement counts: {dist}")
num_shots = sum([dist[k] for okay in dist])
for okay, v in dist.objects():
p = v / num_shots
# 1% confidence interval estimate for a Bernoulli variable
delta = 2.575 * np.sqrt(p*(1-p)/num_shots)
print(f"p({okay}): {np.spherical(p, 4)} ± {np.spherical(delta, 4)}")
print_results(dist)
Measurement counts: {'0': 99661, '1': 339}
p(0) = 0.9966 ± 0.0005
p(1) = 0.0034 ± 0.0005
We get a small chance, round 0.3%, to watch the wrong end result 1. The interval estimate “± 0.0005” refers to a 1% confidence interval estimate for a Bernoulli variable.
The constancy of the output state ρ, relative to the best state |0⟩, is F = ⟨0|ρ|0⟩ = p₀. We have now obtained an estimate of 0.9966 ± 0.0005 for p₀ from the repeated measurements of the circuit output state. However the measurement operation is a priori imperfect (it has its personal error charge). It could add a bias to the p₀ estimate. We assume that these measurement errors are likely to lower the estimated constancy by incorrect measurements of |0⟩ states. On this case, the estimated p₀ shall be a decrease certain on the true constancy F:
F > F̃ = 0.9966 ± 0.0005
Word: We have now obtained estimated chances p₀, p₁ for the diagonal parts of the single-qubit density matrix ρ. We even have an estimated certain on the off-diagonal part |c| < √(p₀ p₁) ~ 0.06. To get an precise estimate for c, we would wish to run a circuit some gates and design a extra advanced reasoning.
Foundation gates
Qiskit gives a lot of quantum gates encoding normal operations on one or two qubits, nonetheless all these gates are encoded within the QPU {hardware} with mixtures of a really small set of bodily operations on the qubits, referred to as foundation gates.
There are three single-qubit foundation gates: X, SX and RZ(λ) and one two-qubit foundation gate: ECR. All different quantum gates are constructed from these constructing blocks. The extra foundation gates are utilized in a quantum circuit, the bigger is the quantum noise. We’ll analyse the noise ensuing from making use of these foundation gates in isolation, when potential, or with a minimal variety of foundation gates, to get a way of quantum noise within the present state of QPU computations.
X gate
We think about the circuit made from a single qubit and an X gate. The output state, within the absence of noise, is X|0⟩ = |1⟩.
# Quantum circuit with a single qubit and an X gate.
# Anticipated output state X|0> = |1>.
qc = QuantumCircuit(1)
qc.x(0)dist, qc_isa = run_circuit(qc, num_shots=100_000)
qc_isa.draw(output="mpl", idle_wires=False, model="iqp")
print_results(dist)
Measurement counts: {'1': 99072, '0': 928}
p(0) = 0.0093 ± 0.0008
p(1) = 0.9907 ± 0.0008
The state constancy of the output state ρ, relative to the best state |1⟩, is
F = ⟨1|ρ|1⟩ = p₁ > F̃ = 0.9907 ± 0.0008
the place we assumed once more that the measurement operation decrease the estimated constancy and we get a decrease certain F̃ on the constancy.
We observe that the constancy is (not less than) round 99.1%, which is a little bit worse than the constancy measured with out the X gate. Certainly, including a gate to the circuit ought to add noise, however there could be one other impact contributing to the degradation of the constancy, which is the truth that the |1⟩ state is a priori much less steady than the |0⟩ state and so the measurement of a |1⟩ state itself might be extra noisy. We is not going to focus on the bodily realisation of a qubit in IBM QPUs, however one factor to bear in mind is that the |0⟩ state has decrease vitality than the |1⟩ state, in order that it’s quantum mechanically extra steady. Consequently, the |1⟩ state can decay to the |0⟩ state by interactions with the environement.
SX gate
We now think about the SX gate, i.e. the “square-root X” gate, represented by the matrix
It transforms the preliminary qubit state |0⟩ into the state
# Quantum circuit with a single qubit and an SX gate.
qc = QuantumCircuit(1)
qc.sx(0)dist, qc_isa = run_circuit(qc, num_shots=100_000)
qc_isa.draw(output="mpl", idle_wires=False, model="iqp")
print_results(dist)
Measurement counts: {'1': 50324, '0': 49676}
p(0) = 0.4968 ± 0.0041
p(1) = 0.5032 ± 0.0041
We observe roughly equal distributions of zeros and ones, which is as anticipated. However we face an issue now. The state constancy can’t be computed from these p₀ and p₁ estimates. Certainly, the constancy of the output state ρ, relative to the best output state SX|0⟩ is
Due to this fact, to get an estimate of F, we additionally must measure c, or somewhat its imaginary half Im(c). Since there isn’t a different measurement we are able to do on the SX gate circuit, we have to think about a circuit with extra gates to judge F, however extra gates additionally means extra sources of noise.
One easy factor we are able to do is so as to add both one other SX gate or an SX⁻¹ gate. Within the former case, the complete circuit implements the X operation and the anticipated remaining state |1⟩, whereas within the latter case, the complete circuit implements the id operation and the anticipated remaining state is |0⟩.
Allow us to think about the case of including an SX gate: the density matrix ρ produced by the primary SX gate will get reworked into
resulting in p’₁ = 1/2— Im(c) = F, within the ultimate case when the second SX gate is freed from quantum noise. In apply the SX gate is imperfect and we are able to solely measure p’₁ = 1/2 — Im(c) — δp = F — δp, the place δp is as a result of noise from the second SX gate. Though it’s theoretically potential that the added noise δp combines with the noise launched by the primary SX gate and ends in a smaller mixed noise, we are going to assume that no such “pleased” cancelation occurs, in order that we have now δp>0. On this case, p’₁ < F provides us a decrease certain on the state constancy F.
qc = QuantumCircuit(1)
qc.sx(0)
qc.barrier() # Prevents simplification of the circuit throughout transpilation.
qc.sx(0)dist, qc_isa = run_circuit(qc, num_shots=100_000)
print_results(dist)
Measurement counts: {'1': 98911, '0': 1089}
p(1): 0.9891 ± 0.0008
p(0): 0.0109 ± 0.0008
We get hold of a decrease certain F > p’₁ = 0.9891 ± 0.0008, on the constancy of the output state ρ for the SX-gate circuit, relative to the best output state SX|0⟩.
We may have thought of the two-gate circuit with an SX gate adopted by an SX⁻¹ gate as an alternative. The SX⁻¹ gate is just not a foundation gate. It’s applied within the QPU as SX⁻¹ = RZ(-π) SX RZ(-π). We count on this setup so as to add extra quantum noise due the presence of extra foundation gates, however in apply we have now measured the next (higher) decrease certain F̃. The reader can test this as an train. We imagine this is because of the truth that the undesirable interactions with the atmosphere are likely to deliver the qubit state to the bottom state |0⟩, bettering incorrectly the decrease certain estimate, so we don’t report this various end result.
RZ(λ) gate
Subsequent we think about the RZ(λ) gate. The RZ(λ) gate is a parametrised gate implementing a rotation across the z-axis by an angle λ/2.
Its impact on the preliminary qubit |0⟩ is simply to multiply it by a part exp(-iλ/2), leaving it in the identical state. Normally, the motion of RZ(λ) on the density matrix of a single qubit is to multiply the off-diagonal coefficient c by exp(iλ), leaving the p₀ and p₁ values of the state unchanged. To measure a non-trivial impact of the RZ(λ) gate, one wants to think about circuits with extra gates. The only is to think about the circuit composing the three gates SX, RZ(λ) and SX, getting ready the state
The anticipated p(0) and p(1) values are
Qiskit gives the likelihood to run parametrised quantum circuits by specifying an array of parameter values, which, along with the ISA circuit, outline a Primitive Unified Bloc (PUB). The PUB is then handed to the sampler to run the circuit with all the desired parameter values.
from qiskit.primitives.containers.sampler_pub_result import SamplerPubResultdef run_parametrised_circuit(
qc: QuantumCircuit,
service: QiskitRuntimeService = service,
params: np.ndarray | None = None,
num_shots: int = 100,
) -> tuple[SamplerPubResult, QuantumCircuit]:
"""Runs the parametrised circuit on backend 'num_shots' occasions.
Returns the PubResult and the ISA circuit."""
# Fetch an obtainable QPU
backend = service.least_busy(operational=True, simulator=False)
goal = backend.goal
pm = generate_preset_pass_manager(goal=goal, optimization_level=1)
# Add mesurement layer
qc_meas = qc.measure_all(inplace=False)
# Outline ISA circuit and PUB
pm = generate_preset_pass_manager(goal=goal, optimization_level=1)
qc_isa = pm.run(qc_meas)
sampler_pub = (qc_isa, params)
# Run the circuit
end result = sampler.run([sampler_pub], photographs=num_shots).end result()
return end result[0], qc_isa
from qiskit.circuit import Parameter# Circuit getting ready the state SX.RZ(a).SX|0> = sin(a/2)|0> + cos(a/2)|1>.
qc = QuantumCircuit(1)
qc.sx(0)
qc.rz(Parameter("a"), 0)
qc.sx(0)
# Outline parameter vary
params = np.linspace(0, 2*np.pi, 21).reshape(-1, 1)
# Run parametrised circuit
pub_result, qc_isa = run_parametrised_circuit(qc, params=params, num_shots=10_000)
qc_isa.draw(output="mpl", idle_wires=False, model="iqp")
bit_array = pub_result.knowledge.meas.bitcount()
print(f"bit_array form: {bit_array.form}")
p0 = (bit_array.form[1] - bit_array.sum(axis=1)) / bit_array.form[1]
p1 = bit_array.sum(axis=1) / bit_array.form[1]
print(f"p(0): {p0}")
print(f"p(1): {p1}")
bit_array form: (21, 10000)
p(0): [0.0031 0.0265 0.095 0.2095 0.3507 0.4969 0.6567 0.7853 0.9025 0.9703
0.9983 0.976 0.901 0.7908 0.6543 0.5013 0.3504 0.2102 0.0982 0.0308
0.0036]
p(1): [0.9969 0.9735 0.905 0.7905 0.6493 0.5031 0.3433 0.2147 0.0975 0.0297
0.0017 0.024 0.099 0.2092 0.3457 0.4987 0.6496 0.7898 0.9018 0.9692
0.9964]
import matplotlib.pyplot as pltx = params/(2*np.pi)
plt.scatter(x, p0)
plt.scatter(x, p1)
plt.plot(x, np.sin(np.pi*x)**2, linestyle="--")
plt.plot(x, np.cos(np.pi*x)**2, linestyle="--")
plt.xlabel("λ/2π")
plt.ylabel("Estimated chances")
plt.legend(["p(0)", "p(1)", "sin(λ/2)^2", "cos(λ/2)^2"])
plt.present()
We see that the estimated chances (blue and orange dots) agree very nicely with the theoretical chances (blue and orange traces) for all examined values of λ.
Right here once more, this doesn’t give us the state constancy. We may give a decrease certain by including one other sequence of gates SX.RZ(λ).SX to the circuit, bringing again the state to |0⟩. As within the case of the SX gate of the earlier part, the estimated F̃ := p’₀ from this 6-gate circuit provides us a decrease certain on the constancy of the F of the 3-gate circuit, assuming the additional gates decrease the output state constancy.
Allow us to compute this decrease certain F̃ for one worth, λ = π/4.
# Circuit implementing SX.RZ(π/4).SX.SX.RZ(π/4).SX|0> = |0>
qc = QuantumCircuit(1)
qc.sx(0)
qc.rz(np.pi/4, 0)
qc.sx(0)
qc.barrier() # Prevents circuit simplifications.
qc.sx(0)
qc.rz(np.pi/4, 0)
qc.sx(0)dist, qc_isa = run_circuit(qc, num_shots=100_000)
qc_isa.draw(output="mpl", idle_wires=False, model="iqp")
dist = pub_result.knowledge.meas.get_counts()
print_results(dist)
Measurement counts: {'0': 99231, '1': 769}
p(0): 0.9923 ± 0.0007
p(1): 0.0077 ± 0.0007
We discover a fairly excessive decrease certain estimate F̃ = 0.9923 ± 0.0007.
Digression: a decrease certain estimate process
The above case confirmed that we are able to estimate a decrease certain on the constancy F of the output state of a circuit by extending the circuit with its inverse operation and measuring the chance of getting the preliminary state again.
Allow us to think about an n-qubit circuit getting ready the state |ψ⟩ = U|0,0, … ,0⟩. The state constancy of the output density matrix ρ is given by
U⁻¹ρU is the density matrix of the circuit composed of a (noisy) U gate and a noise-free U⁻¹ gate. F is the same as the constancy of the |0,0, …, 0⟩ state of this 2-gate circuit. If we had such a circuit, we may pattern it and measure the chance of (0, 0, …, 0) as the specified constancy F.
In apply we don’t have a noise-free U⁻¹ gate, however solely a loud U⁻¹ gate. By sampling this circuit (noisy U, adopted by noisy U⁻¹) and measuring the chance of the (0, 0, …, 0) consequence, we get hold of an estimate F̃ of F — δp, with δp the noise overhead added by the U⁻¹ operation (and the measurement operation). Underneath the belief δp>0, we get hold of a decrease certain F > F̃. This assumption is just not essentially true as a result of the noisy interactions with the atmosphere probably are likely to deliver the qubits to the bottom state |0,0, …, 0⟩, however for “advanced sufficient” operations U, this impact needs to be subdominant relative to the noise launched by the U⁻¹ operation. We have now used this strategy to estimate the constancy within the SX.RZ(λ).SX circuit above. We’ll use it once more to estimate the constancy of the ECR-gate and the 3-qubit state from the preliminary circuit we thought of.
ECR gate
The ECR gate (Echoed Cross-Resonance gate) is the one two-qubit foundation gate within the Eagle household of IBM QPUs (different households assist the CZ or CX gate as an alternative, see tables of gates). It’s represented within the computational foundation by the 4×4 matrix
Its motion on the preliminary 2-qubit state is
The measurements of a noise-free ECR gate circuit are (0,1) with chance 1/2 and (1,1) with chance 1/2. The result (0,0) and (1,0) should not potential within the noise-free circuit.
qc = QuantumCircuit(2)
qc.ecr(0, 1)
dist, qc_isa = run_circuit(qc, num_shots=100_000)qc_isa.draw(output="mpl", idle_wires=False, model="iqp")
print_results(dist)
Measurement counts: {'11': 49254, '01': 50325, '00': 239, '10': 182}
p(11): 0.4925 ± 0.0041
p(01): 0.5032 ± 0.0041
p(00): 0.0024 ± 0.0004
p(10): 0.0018 ± 0.0003
We observe a distribution of measured classical bits roughly agreeing with the anticipated ultimate distribution, however the presence of quantum errors is revealed by the presence of some (0,0) and (1, 0) outcomes.
The constancy of the output state ρ is given by
As within the case of the SX-gate circuit, we can’t straight estimate the constancy of the ρ state ready by the ECR-gate circuit by measuring the output bits of the circuit, because it relies on off-diagonal phrases within the ρ matrix.
As a substitute we are able to comply with the process described within the earlier part and estimate a decrease certain on F by contemplating the circuit with an added ECR⁻¹ gate. Since ECR⁻¹ = ECR, we think about a circuit with two ECR gates.
qc = QuantumCircuit(2)
qc.ecr(0, 1)
qc.barrier() # Prevents circuit simplifications.
qc.ecr(0, 1)
dist, qc_isa = run_circuit(qc, num_shots=100_000)
qc_isa.draw(output="mpl", idle_wires=False, model="iqp")
print_results(dist)
Measurement counts: {'00': 99193, '01': 153, '10': 498, '11': 156}
p(00): 0.9919 ± 0.0007
p(01): 0.0015 ± 0.0003
p(10): 0.005 ± 0.0006
p(11): 0.0016 ± 0.0003
We discover the estimated decrease certain F > 0.9919 ± 0.0007 on the ρ state ready by the ECR-gate circuit.
3-qubit state constancy
To shut the loop, in our remaining instance, allow us to compute a decrease certain on the state constancy of the 3-qubit state circuit which we thought of first. Right here once more, we add the inverse operation to the circuit, bringing again the state to |0,0,0⟩ and measure the circuit outcomes.
qc = QuantumCircuit(3)
qc.h(0)
qc.cx(0, 1)
qc.cx(0, 2)
qc.barrier(). # Prevents circuit simplifications.
qc.cx(0, 2)
qc.cx(0, 1)
qc.h(0)
qc.draw('mpl')
dist, qc_isa = run_circuit(qc, num_shots=100_000)
qc_isa.draw(output="mpl", idle_wires=False, model="iqp")
print_results(dist)
Measurement counts: {'000': 95829, '001': 1771, '010': 606, '011': 503, '100': 948, '101': 148, '111': 105, '110': 90}
p(000): 0.9583 ± 0.0016
p(001): 0.0177 ± 0.0011
p(010): 0.0061 ± 0.0006
p(011): 0.005 ± 0.0006
p(100): 0.0095 ± 0.0008
p(101): 0.0015 ± 0.0003
p(111): 0.001 ± 0.0003
p(110): 0.0009 ± 0.0002
We discover the constancy decrease certain F̃ = p’((0,0,0)) = 0.9583 ± 0.0016 for the 3-qubit state circuit.