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(create_model(main))
show(qprog)
Opening: https://platform.classiq.io/circuit/109c864c-1ee0-4886-86df-1a66b8f1c3f7?version=0.41.0.dev39%2B79c8fd0855
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 = synthesize(create_model(main))
show(qprog)
Opening: https://platform.classiq.io/circuit/ad6f8b4d-efcb-492e-8e29-624ff3f60a16?version=0.41.0.dev39%2B79c8fd0855