> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ionq.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Writing Quantum Programs

<Tip>
  For the best results, please submit quantum programs in the `ionq.circuit.v0` format, as demonstrated below.
</Tip>

In the compilation and optimization process, your submitted circuit will be converted to an equivalent, optimized circuit expressed in terms of IonQ's native gates, which may involve combining or canceling out some operations. If you wish to guarantee that the quantum computer executes the exact series of operations that you define, you can submit a circuit using our [native gates](/api-reference/v0.3/native-gates-api), which will bypass our compiler.

For more examples and the full API specification for defining circuits, refer to [the API reference](/api-reference/v0.3/jobs/create-a-job).

To write a quantum program using [Qiskit](/guides/sdks/qiskit) or another SDK, refer to our SDK guides.

***

## Bell State

We can create a maximally entangled [Bell state](https://en.wikipedia.org/wiki/Bell_state) by applying a Hadamard gate to a single qubit, and applying a controlled-not gate to a second qubit.

Half of the time the second qubit will be measured as $|0⟩$, the other half will be measured as $|1⟩$.

```json theme={null}
{
    "format": "ionq.circuit.v0",
    "gateset": "qis",
    // The fields above are optional, as they are the default.
    "qubits": 2,
    "circuit": [
        {
        "gate": "h",
        "target": 0
        },
        {
        "gate": "cnot",
        "target": 1,
        "control": 0
        }
    ]
}
```

***

## GHZ State

We can create a three qubit [GHZ state](https://en.wikipedia.org/wiki/Greenberger%E2%80%93Horne%E2%80%93Zeilinger_state) by first applying a Hadamard gate to a single qubit, and then using it as the control qubit for a series of controlled-not gates.

```json theme={null}
{
    "qubits": 4,
    "circuit": [
        {
        "gate": "h",
        "target": 0
        },
        {
        "gate": "cnot",
        "control": 0,
        "target": 1
        },
        {
        "gate": "cnot",
        "control": 0,
        "target": 2
        },
        {
        "gate": "cnot",
        "control": 0,
        "target": 3
        }
    ]
    }
```

***

## Toffoli gate

The [Toffoli gate](https://en.wikipedia.org/wiki/Toffoli_gate), or controlled-controlled-not gate, is a universal reversible logic gate. We can simply apply a not to our target qubit, with two control qubits provided via array.

```json theme={null}
{
    "qubits": 3,
    "circuit": [
        {
        "gate": "not",
        "target": 0,
        "controls": [1, 2]
        }
    ]
}
```

***

## Supported Gates

For actual execution, gates will be compiled into optimal operations for our trapped ion hardware. For convenience, we provide a more expressive gateset for programming.

We accept these gates as well as their controlled and multi-controlled variants:

| Gate   | Description                                    |
| ------ | ---------------------------------------------- |
| `x`    | Pauli X gate                                   |
| `y`    | Pauli Y gate                                   |
| `z`    | Pauli Z gate                                   |
| `rx`   | X-axis rotation                                |
| `ry`   | Y-axis rotation                                |
| `rz`   | Z-axis rotation                                |
| `h`    | Hadamard gate                                  |
| `not`  | Convenient alias for Pauli-X gate              |
| `cnot` | Convenient alias for controlled-not gate       |
| `s`    | S gate                                         |
| `si`   | Conjugate transpose of S gate                  |
| `t`    | T gate                                         |
| `ti`   | Conjugate transpose of T gate                  |
| `v`    | Square root of not gate                        |
| `vi`   | Conjugate transpose of square-root-of-not gate |
| `swap` | Swaps two qubits                               |

Each operation in a circuit specifies a `gate` and a `target` qubit index (or a list of multiple `targets`). Rotation gates also specify a `rotation` in radians.

In addition, any gate can be expressed as a controlled gate by specifying a `control` qubit, or as its multi-controlled variant by specifying a list of up to seven `controls` (for any gate except `swap`). This can often be used to simplify the circuit's description. In general, circuits expressed in fewer QIS gates will be further optimized for runtime, so using multi-controlled variants of gates is recommended.

Examples:

* Hadamard gate: `{"gate": "h", "target": 0}`
* Controlled-not gate: `{"gate": "cnot", "target": 1, "control": 0}`
* Toffoli gate (multi-controlled not gate): `{"gate": "not", "target": 0, "controls": [1, 2]}`
* Rx gate with $\pi/2$ rotation: `{"gate": "rx", "target": 0, "rotation": 1.5708}`
* Swap gate: `{"gate": "swap", "targets": [0,1]}`

For more examples and the full API specification for defining circuits, refer to [the API reference](/api-reference/v0.3/jobs/create-a-job).

## Native Specification

For information about writing quantum programs using IonQ's hardware-native gate set, refer to our guides on [getting started with native gates](/guides/getting-started-with-native-gates) and [using native gates with the IonQ API](/api-reference/v0.3/native-gates-api).

***

## Other Formats (experimental)

Support for submitting programs in [QASM/OpenQASM](https://github.com/Qiskit/openqasm/) and [Quipper](https://www.mathstat.dal.ca/~selinger/quipper/) is currently experimental. If you use these languages, we will compile your code to a logically-equivalent representation using our [supported gates](#supported-gates). (For billing purposes, we'll calculate your program's resource requirements **after** it's been compiled this way.)

### OpenQASM

```json theme={null}
{
  "format": "openqasm",
  "data": "string"
}
```

### QASM

```json theme={null}
{
  "format": "qasm",
  "data": "string"
}
```

### Quipper

```json theme={null}
{
  "format": "quipper",
  "data": "string"
}
```

***

<Note>
  Is there a language format you'd like to see supported? [Drop us a line](mailto:support@ionq.com) and let us know.
</Note>
