> ## Documentation Index
> Fetch the complete documentation index at: https://prod-mint.classiq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# GHZ State Preparation

<Card title="View on GitHub" icon="github" href="https://github.com/Classiq/classiq-library/blob/main/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_ghz_state.ipynb">
  Open this notebook in GitHub to run it yourself
</Card>

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.

## Syntax

Function: `prepare_ghz_state`

Arguments:

* `size: CInt`
* `q: Output[QArray[QBit]]`

## Example

`prepare_ghz_state` on 5 qubits

```python theme={null}
from classiq import *


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


qmod = create_model(main)
```

```python theme={null}

qprog = synthesize(qmod)
```
