Skip to content

GHZ State Preparation

Use the prepare_ghz_state function to create a Greenberger-Horne-Zeilinger (GHZ) state. i.e., a balanced superposition of all ones and all zeros, on an arbitrary number of qubits.


Function: prepare_ghz_state


  • size: CInt
  • q: Output[QArray[QBit]]


prepare_ghz_state on 5 qubits

from classiq import Output, QArray, QBit, create_model, prepare_ghz_state, qfunc

def main(x: Output[QArray[QBit]]):
    prepare_ghz_state(5, x)

qmod = create_model(main)
from classiq import synthesize, write_qmod

write_qmod(qmod, "prepare_ghz_state")
qprog = synthesize(qmod)