GHZ State
The GHZ state, a highly entangeld state entengaling all qubits in a circuit.
\[|GHZ\rangle = \frac{|0\rangle^{\otimes n} + |1\rangle^{\otimes n}}{\sqrt{2}}\]
Create a function that will generate a GHZ state for n
qubits. Use the Classiq build in repeat
no classical loops. An example circuit is shown below. As you can see to create this circuit, there are two steps:
-
Apply the H gate to the first qubit.
-
Perform a CNOT gate between the first qubit and all other qubits, or perform CNOT gates like seen in the image below.
The Classiq library also has a QHZ state preparation build in. That implementation can be found here.
from classiq import *
@qfunc
def main(reg: Output[QArray]):
allocate(6, reg)
# your code here
pass
qprog = synthesize(main)
show(qprog)
Opening: https://platform.classiq.io/circuit/2uFzfHGxMGhCM1qrYeHzjojVohD?version=0.70.0
The full solution for your reference
from classiq import *
@qfunc
def main(reg: Output[QArray]):
allocate(6, reg)
H(reg[0])
repeat(
count=reg.len - 1,
iteration=lambda index: CX(ctrl=reg[index], target=reg[index + 1]),
)
qprog_solution = synthesize(main)
show(qprog_solution)
Opening: https://platform.classiq.io/circuit/2uFzfUVluMz6gBPnnlJhS8lSFKf?version=0.70.0