import numpy as np
from qiskit import QuantumCircuit
from qiskit.circuit import Parameter
from qiskit.quantum_info import SparsePauliOp
from qiskit_ibm_runtime import QiskitRuntimeService, Estimator, Session
import matplotlib.pyplot as plt
import matplotlib.ticker as tck
How local reality doesn’t hold true for quantum mechanics!
The historical development of quantum mechanics is filled with agitated discussions about the true nature of reality and the extent to which quantum mechanics can explain it. Given the spectacular empirical success of quantum mechanics, it was going to be clear that people would not simply give it up just because some of its aspects were hard to reconcile with intuition.
At the root of these different points of views was the question of the nature of measurement. We know there is an element of randomness in quantum measurements, but is that really so? Is there a sneaky way by which the Universe has already decided beforehand which value a given measurement is going to yield at a future time? This hypothesis was the basis for different hidden variable theories. But these theories did not only need to explain randomness at the single particle level. They also needed to explain what happens when different observers measure different parts of a multi-partite entangled system! This went beyond just hidden variable theories. Now a local hidden variable theory was needed in order to reconcile the observations of quantum mechanics with a Universe in which local reality was valid.
What is local reality? In an Universe where locality holds, it should be possible to separate two systems so far in space that they could not interact with each other. The concept of reality is related to whether a measurable quantity holds a particular value in the absence of any future measurement.
In 1963, John Stewart Bell published what could be argued as one of the most profound discoveries in the history of science. Bell stated that any theory invoking local hidden variables could be experimentally ruled out. In this section we are going to see how, and we will run a real experiment that demonstrates so! (with some remaining loopholes to close…)
It’s an experiment on a quantum computer to demonstrate the violation of the CHSH inequality with the Estimator primitive.
The violation of the CHSH inequality is used to show that quantum mechanics is incompatible with local hidden-variable theories. This is an important experiment for understanding the foundation of quantum mechanics. The 2022 Nobel Prize for Physics was awarded to Alain Aspect, John Clauser and Anton Zeilinger for their pioneering work in quantum information science, and in particular, their experiments with entangled photons demonstrating violation of Bell’s inequalities. An experimental method by which one can test Bell’s inequality was put forth by Clauser, Horne, Shimony, and Holt (CHSH) in 1969, and forms the basis for the experiment conducted here.
CHSH Inequality
Imagine Alice and Bob are given each one part of a bipartite entangled system. Each of them then performs two measurements on their part in two different bases. Let’s call Alice’s bases A and a and Bob’s B and b. What is the expectation value of the quantity
\[ \langle CHSH \rangle = \langle AB \rangle - \langle Ab \rangle + \langle aB \rangle + \langle ab \rangle ? \]
Now, Alice and Bob have one qubit each, so any measurement they perform on their system (qubit) can only yield one of two possible outcomes: +1 or -1. Note that whereas we typically refer to the two qubit states as \(|0\rangle\) and \(|1\rangle\), these are eigenstates, and a projective measurement will yield their eigenvalues, +1 and -1, respectively.
Therefore, if any measurement of A, a, B, and b can only yield \(\pm 1\), the quantities \((B-b)\) and \((B+b)\) can only be 0 or \(\pm 2\). And thus, the quantity \(A(B-b) + a(B+b)\) can only be either +2 or -2, which means that there should be a bound for the expectation value of the quantity we have called
\[ |\langle CHSH \rangle| = |\langle AB \rangle - \langle Ab \rangle + \langle aB \rangle + \langle ab \rangle| \le 2. \]
Create Entangled Qubit Pair
Next we want to test the \(CHSH\) observable on an entangled pair, for example the maximally-entangled Bell state \[
|\Phi\rangle = \frac{1}{\sqrt{2}} \left(|00\rangle + |11\rangle \right)
\] which is created with a Hadamard gate followed by a CNOT with the target on the same qubit as the Hadamard. Due to the simplifaction of measuring in just the \(X\)- and \(Z\)-bases as discussed above, we will rotate the Bell state around the Bloch sphere which is equivalant to changing the measurement basis. This can be done by applying an \(R_y(\theta)\) gate where \(\theta\) is a Parameter
to be specified at the Estimator
API call. This produces the state \[
|\psi\rangle = \frac{1}{\sqrt{2}} \left(\cos(\theta/2) |00\rangle + \sin(\theta/2)|11\rangle \right)
\]
= Parameter("$\\theta$")
theta
= QuantumCircuit(2)
chsh_circuits_no_meas 0)
chsh_circuits_no_meas.h(0, 1)
chsh_circuits_no_meas.cx(0)
chsh_circuits_no_meas.ry(theta, "mpl") chsh_circuits_no_meas.draw(
Next we need to specify a Sequence
of Parameter
s that show a clear violation of the CHSH Inequality, namely \[
|\langle CHSH \rangle| > 2.
\]
We will analyze the results and plot them against the measurement angle and will see that for certain range of measurement angles, the expectation values of CHSH quantities or, which demonstrates the violation of the CHSH inequality.
= 21
number_of_phases = np.linspace(0, 2 * np.pi, number_of_phases)
phases # Phases need to be expressed as list of lists in order to work
= [[ph] for ph in phases] individual_phases
= QiskitRuntimeService()
service ="ibmq_qasm_simulator" #service.get_backend("ibmq_manila") backend
= SparsePauliOp.from_list([("ZZ", 1)])
ZZ = SparsePauliOp.from_list([("ZX", 1)])
ZX = SparsePauliOp.from_list([("XZ", 1)])
XZ = SparsePauliOp.from_list([("XX", 1)])
XX
= [ZZ, ZX, XZ, XX]
ops = []
chsh_est
# Simulator
with Session(backend=backend):
= Estimator()
estimator for op in ops:
= estimator.run(
job =[chsh_circuits_no_meas] * len(individual_phases),
circuits=[op] * len(individual_phases),
observables=individual_phases,
parameter_values
)= job.result()
est_result chsh_est.append(est_result)
# <CHSH1> = <AB> - <Ab> + <aB> + <ab>
= chsh_est[0].values - chsh_est[1].values + chsh_est[2].values + chsh_est[3].values
chsh1_est
# <CHSH2> = <AB> + <Ab> - <aB> + <ab>
= chsh_est[0].values + chsh_est[1].values - chsh_est[2].values + chsh_est[3].values chsh2_est
chsh1_est
array([ 2. , 1.2535, 0.4515, -0.437 , -1.2705, -2.0035, -2.504 ,
-2.8055, -2.79 , -2.5305, -1.9595, -1.3045, -0.456 , 0.45 ,
1.2835, 2.0445, 2.4955, 2.8115, 2.7665, 2.5245, 2.046 ])
chsh2_est
array([ 2. , 2.5435, 2.8155, 2.806 , 2.5455, 1.9965, 1.303 ,
0.4495, -0.458 , -1.2915, -2.0405, -2.4915, -2.753 , -2.801 ,
-2.5375, -1.9555, -1.2975, -0.4335, 0.4305, 1.2725, 1.954 ])
= plt.subplots(figsize=(10, 6))
fig, ax # results from hardware
/ np.pi, chsh1_est, "o-", label="CHSH1", zorder=3)
ax.plot(phases / np.pi, chsh2_est, "o-", label="CHSH2", zorder=3)
ax.plot(phases # classical bound +-2
=2, color="0.9", linestyle="--", )
ax.axhline(y=-2, color="0.9", linestyle="--")
ax.axhline(y# quantum bound, +-2√2
=np.sqrt(2) * 2, color="0.9", linestyle="-.")
ax.axhline(y=-np.sqrt(2) * 2, color="0.9", linestyle="-.")
ax.axhline(y/ np.pi, 2, 2 * np.sqrt(2), color="0.6", alpha=0.7)
ax.fill_between(phases / np.pi, -2, -2 * np.sqrt(2), color="0.6", alpha=0.7)
ax.fill_between(phases # set x tick labels to the unit of pi
"%g $\pi$"))
ax.xaxis.set_major_formatter(tck.FormatStrFormatter(=0.5))
ax.xaxis.set_major_locator(tck.MultipleLocator(base# set title, labels, and legend
"Violation of CHSH Inequality")
plt.title("Theta")
plt.xlabel("CHSH witness")
plt.ylabel(; plt.legend()