GHZ state
The Greenberger–Horne–Zeilinger state (GHZ state) is a maximally entangled, non-biseparable quantum state that requires atleast three qubits. For a three qubit system, the GHZ state is described as follows:
Measuring one of the qubits \(|0\rangle\) or \(|1\rangle\) leaves the other two qubits either \(|00\rangle\) or \(|11\rangle\). The GHZ state is used in quantum communications, quantum crptography, and in fault tolent protocols such as the quantum Byzantine agreement.
The quantum circuit for creating a 3-qubit GHZ state is illustrated below:
┌───┐
q0:|0> ■─┤ H ├───■────────────
└───┘ │
┌─┴─┐
q1:|0> ■───────┤ X ├────■────
└───┘ │
┌─┴─┐
q2:|0> ■──────────────┤ X ├───
└───┘
This example creates a 50 qubit GHZ state. To implement the GHZ state using Quantum Rings SDK, first import the required modules:
Note
Be sure to use your API token and your account name.
import QuantumRingsLib
from QuantumRingsLib import QuantumRegister, AncillaRegister, ClassicalRegister, QuantumCircuit
from QuantumRingsLib import QuantumRingsProvider
from QuantumRingsLib import job_monitor
from QuantumRingsLib import JobStatus
from matplotlib import pyplot as plt
import numpy as np
The next step is to obtain the backend:
provider = QuantumRingsProvider(token =<YOUR_TOKEN_HERE>, name=<YOUR_ACCOUNT_NAME_HERE>)
backend = provider.get_backend("scarlet_quantum_rings")
numberofqubits = 50
shots = 100
provider.active_account()
The third step is to construct the quantum circuit and execute it:
q = QuantumRegister(numberofqubits , 'q')
c = ClassicalRegister(numberofqubits , 'c')
qc = QuantumCircuit(q, c)
qc.h(0);
for i in range (qc.num_qubits - 1):
qc.cnot(i, i + 1);
qc.measure_all();
job = backend.run(qc, shots)
job_monitor(job)
result = job.result()
counts = result.get_counts()
Finally we can plot the results as a histogram:
fig, ax = plt.subplots(figsize =(10, 7))
plt.xlabel("States")
plt.ylabel("Counts")
mylist = [key for key, val in counts.items() for _ in range(val)]
unique, inverse = np.unique(mylist, return_inverse=True)
bin_counts = np.bincount(inverse)
plt.bar(unique, bin_counts)
maxFreq = max(counts.values())
plt.ylim(ymax=np.ceil(maxFreq / 10) * 10 if maxFreq % 10 else maxFreq + 10)
# Show plot
plt.show()
An example histogram is shown below. It could be different for you due to the statistics of the final state.