Learning Home Catalog Composer Lab
Learning
Home Catalog Composer Lab Return to tutorial
Learning
CHSH inequality
BackgroundSetupStep 1: Map classical inputs to a quantum problemCreate a parameterized CHSH circuitCreate a list of phase values to be assigned laterObservablesStep 2: Optimize problem for quantum execution.Step 3: Execute using Qiskit Primitives.Step 4: Post-process, return result in classical format.

CHSH inequality

Category

Workflow example

Topics

Scheduling
Download notebook Download notebook Open in Quantum Lab Open in Quantum Lab

Background

In this tutorial, you will run an experiment on a quantum computer to demonstrate the violation of the CHSH inequality with the Estimator primitive.

The CHSH inequality, named after the authors Clauser, Horne, Shimony, and Holt, is used to experimentally prove Bell's theorem (1969). This theorem asserts that local hidden variable theories cannot account for some consequences of entanglement in quantum mechanics. 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 in part for their pioneering work in quantum information science, and in particular, for their experiments with entangled photons demonstrating violation of Bell’s inequalities.

For this experiment, we will create an entangled pair on which we measure each qubit on two different bases. We will label the bases for the first qubit AA and aa and the bases for the second qubit BB and bb. This allows us to compute the CHSH quantity S1S_1:

S1=A(B−b)+a(B+b).S_1 = A(B-b) + a(B+b).

Each observable is either +1+1 or −1-1. Clearly, one of the terms B±bB\pm b must be 00, and the other must be ±2\pm 2. Therefore, S1=±2S_1 = \pm 2. The average value of S1S_1 must satisfy the inequality:

∣⟨S1⟩∣≤2.|\langle S_1 \rangle|\leq 2.

Expanding S1S_1 in terms of AA, aa, BB, and bb results in:

∣⟨S1⟩∣=∣⟨AB⟩−⟨Ab⟩+⟨aB⟩+⟨ab⟩∣≤2|\langle S_1 \rangle| = |\langle AB \rangle - \langle Ab \rangle + \langle aB \rangle + \langle ab \rangle| \leq 2

You can define another CHSH quantity S2S_2:

S2=A(B+b)−a(B−b),S_2 = A(B+b) - a(B-b),

This leads to another inequality:

∣⟨S2⟩∣=∣⟨AB⟩+⟨Ab⟩−⟨aB⟩+⟨ab⟩∣≤2|\langle S_2 \rangle| = |\langle AB \rangle + \langle Ab \rangle - \langle aB \rangle + \langle ab \rangle| \leq 2

If quantum mechanics can be described by local hidden variable theories, the previous inequalities must hold true. However, as is demonstrated in this notebook, these inequalities can be violated in a quantum computer. Therefore, quantum mechanics is not compatible with local hidden variable theories.

If you want to learn more theory, explore Entanglement in Action with John Watrous.

You will create an entangled pair between two qubits in a quantum computer by creating the Bell state ∣Φ+⟩=∣00⟩+∣11⟩2|\Phi^+\rangle = \frac{|00\rangle + |11\rangle}{\sqrt{2}}. Using the Estimator primitive, you can directly obtain the expectation values needed (⟨AB⟩,⟨Ab⟩,⟨aB⟩\langle AB \rangle, \langle Ab \rangle, \langle aB \rangle, and ⟨ab⟩\langle ab \rangle) to calculate the expectation values of the two CHSH quantities ⟨S1⟩\langle S_1\rangle and ⟨S2⟩\langle S_2\rangle. Before the introduction of the Estimator primitive, you would have to construct the expectation values from the measurement outcomes.

You will measure the second qubit in the ZZ and XX bases. The first qubit will be measured also in orthogonal bases, but with an angle with respect to the second qubit, which we are going to sweep between 00 and 2π2\pi. As you will see, the Estimator primitive makes running parameterized circuits very easy. Rather than creating a series of CHSH circuits, you only need to create one CHSH circuit with a parameter specifying the measurement angle and a series of phase values for the parameter.

Finally, you will analyze the results and plot them against the measurement angle. You will see that for certain range of measurement angles, the expectation values of CHSH quantities ∣⟨S1⟩∣>2|\langle S_1\rangle| > 2 or ∣⟨S2⟩∣>2|\langle S_2\rangle| > 2, which demonstrates the violation of the CHSH inequality.

Setup

Authenticate to run code cells
Reset Copy to clipboard

Output:

Authenticate to run code cells
Reset Copy to clipboard

Output:

'ibmq_mumbai'

Step 1: Map classical inputs to a quantum problem

Create a parameterized CHSH circuit

First, we write the circuit with the parameter θ\theta, which we call theta. The Estimator primitive can enormously simplify circuit building and output analysis by directly providing expectation values of observables. Many problems of interest, especially for near-term applications on noisy systems, can be formulated in terms of expectation values. For maximum generalization, the Estimator primitive requires circuits with no measurements.

Authenticate to run code cells
Reset Copy to clipboard

Output:

Create a list of phase values to be assigned later

After creating the parameterized CHSH circuit, you will create a list of phase values to be assigned to the circuit in the next step. You can use the following code to create a list of 21 phase values range from 00 to 2π2 \pi with equal spacing, that is, 00, 0.1π0.1 \pi, 0.2π0.2 \pi, ..., 1.9π1.9 \pi, 2π2 \pi.

Authenticate to run code cells
Reset Copy to clipboard

Output:

Observables

Now we need observables from which to compute the expectation values. In our case we are looking at orthogonal bases for each qubit, letting the parameterized Y−Y- rotation for the first qubit sweep the measurement basis nearly continuously with respect to the second qubit basis. We will therefore choose the observables ZZZZ, ZXZX, XZXZ, and XXXX.

Authenticate to run code cells
Reset Copy to clipboard

Output:

Step 2: Optimize problem for quantum execution.

Authenticate to run code cells
Reset Copy to clipboard

Output:

Step 3: Execute using Qiskit Primitives.

In order to execute the entire experiment in one call to the Estimator we need to batch the circuit and operators together, repeating each for the requested number_of_phases points.

Authenticate to run code cells
Reset Copy to clipboard

Output:

We can create a Qiskit Runtime Estimator primitive to compute our expectation values, and the Batch context manager to run our non-iterative workload.

Authenticate to run code cells
Reset Copy to clipboard

Output:

Authenticate to run code cells
Reset Copy to clipboard

Output:

The individual expectation values can then be extracted from the batched results:

Authenticate to run code cells
Reset Copy to clipboard

Output:

Step 4: Post-process, return result in classical format.

After running the circuits, we need to build the CHSH witness functions. We first build the quantities ⟨AB⟩\langle AB \rangle, ⟨Ab⟩\langle Ab \rangle, ⟨aB⟩\langle aB \rangle, and ⟨ab⟩\langle ab \rangle, by looking at the parity of the outcomes for the four families of circuits we built (two measurement bases for each of the two qubits). Then we use those quantities to build the witness functions as defined previously.

Authenticate to run code cells
Reset Copy to clipboard

Output:

Note that now we do not have to build the observables ourselves because they are returned to us! The computed expectation values are given in result.values. What comes back is a very small payload of data.

Authenticate to run code cells
Reset Copy to clipboard

Output:

In the figure, the red dashed lines delimit the classical bounds (±2\pm 2) and the dash-dotted blue lines delimit the quantum bounds (±22\pm 2\sqrt{2}). You can see that the experimental results resemble the general trend of the simulated results and there are regions where the CHSH witness quantities exceeds the classical bounds. Congratulations! You have successfully demonstrated the violation of CHSH inequality in a real quantum system!

Authenticate to run code cells
Reset Copy to clipboard

Output:

'0.19.1'
Authenticate to run code cells
Reset Copy to clipboard

Output:

'1.0.0rc1'

Was this page helpful?

YesNo