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

# Clifford+T Synthesis

#### Haiqu.clifford\_t\_synthesis(circuit, total\_t\_gate\_budget=None, gate\_t\_gate\_budget=None, total\_precision\_tolerance=None, gate\_precision\_tolerance=None, max\_trasyn\_budget=13, exact\_spectral\_norm=False)

Synthesizes a circuit into a Clifford+T approximation. The synthesis can be given either a target T-gate budget for
the entire circuit, a T-gate budget per gate, a minimum precision tolerance for the entire circuit, or a per gate
minimum precision tolerance. Precision tolerance for a gate U\_i with approximation V\_i is defined using the spectral
norm distance minimized over global phase ψ, ε\_i = min\_ψ ||U\_i - V\_i e^{iψ}||\_2. Precision tolerance for the total
circuit is taken as the sum of spectral norm distances for each gate, Σ\_i ε\_i.

The two methods used are:
: 1. GridSynth - Approximates a general Z-rotation by mapping the angle and a given precision tolerance onto a
: two-dimensional grid where exact factorization is possible. See [https://arxiv.org/pdf/1403.2975](https://arxiv.org/pdf/1403.2975).
The current implementation uses GridSynth if a target precision tolerance is given or if the per
gate T-gate budget exceeds 'max\_trasyn\_budget'.
2\. TRASYN - Uses tensor networks to probabilistically find the best approximation to a general U3 gate available
: given a specific T-gate budget. See [https://arxiv.org/pdf/2503.15843](https://arxiv.org/pdf/2503.15843). TRASYN often leads to a circuit
with fewer T-gates than GridSynth. However, computing times are proportional to the per-gate budget.
TRASYN is used when the gate T-gate budget is less than or equal to 'max\_trasyn\_budget'.

If both a target T-gate budget and a target precision tolerance are given, the T-gate budget is used and tolerance is
ignored. If both a total and gate budget/tolerance are given, the total is used instead of the gate budget/tolerance.
If no variables are given, the synthesis proceeds with total\_precision\_tolerance = 1e-8.

NOTE: A minimum precision tolerance (1e-13) before numerical inaccuracies become considerable leads to a cap on the
maximum number of T-gates possible in the output circuit.

The synthesis runs in the Haiqu cloud as a hybrid job (see [`flow()`](../index.md#haiqu.sdk.quantum_haiqu.Haiqu.flow)), and this method waits for it to finish.
The job's program is an [`InputLayer`](../run/flow.md#haiqu.sdk.hybrid.layers.InputLayer) followed by a
[`CliffordTSynthesisLayer`](../run/flow.md#haiqu.sdk.hybrid.layers.CliffordTSynthesisLayer) with the options given here, which ends the program. The
synthesized circuit is logged to the current experiment and linked to the input circuit.

* **Parameters:**
  * **circuit** (*QuantumCircuit* *|* *CircuitModel*) -- The circuit to synthesize. All of its parameters must be bound.
  * **total\_t\_gate\_budget** (*int* *,* *optional*) -- The target T-gate budget for the entire circuit.
  * **gate\_t\_gate\_budget** (*int* *,* *optional*) -- The target T-gate budget for each non-Clifford rotation.
  * **total\_precision\_tolerance** (*float* *,* *optional*) -- The precision tolerance for the entire circuit. Must be greater or equal
    to 1e-13.
  * **gate\_precision\_tolerance** (*float* *,* *optional*) -- The precision tolerance to use for GridSynth for each Rz gate. Must be
    greater than or equal to 1e-13.
  * **max\_trasyn\_budget** (*int* *,* *optional*) -- The maximum T-gate budget we allow before switching from TRASYN to GridSynth.
    Must be between 0 and 65 (inclusive). Defaults to 13. `None` uses the
    synthesis default, which is also 13.
  * **exact\_spectral\_norm** (*bool* *,* *optional*) -- Whether to also compute the exact spectral norm distance between the whole
    circuit and its approximation, from their full unitaries. Its cost grows
    exponentially with the width, so it is only available for circuits with 10
    or fewer qubits. Defaults to False.
* **Returns:**
  The synthesized Clifford+T circuit, logged to the current experiment.
  info (dict): Information dictionary about the synthesis process, with keys:
  > * full\_synthesis\_time: Time required for the entire Clifford+T synthesis process.
  > * input\_circuit\_properties (dict): Properties of the input circuit, with keys:
  >   > * num\_t\_gates: Number of T-gates that don't require synthesis.
  >   > * num\_gates\_to\_synthesize:  Number of non-Clifford gates to synthesize.
  >   > * total\_num\_non\_clifford\_gates: Total number of non-Clifford gates.
  > * output\_circuit\_properties (dict): Properties of the output circuit, with keys:
  >   > * t\_gate\_count: Total number of T-gates in the synthesized circuit.
  >   > * t\_gate\_depth: T-gate depth of the synthesized circuit.
  >   > * overall\_spectral\_norm: Spectral norm of the difference between the unitary matrices of the
  >   >   original and synthesized circuits. Only calculated when `exact_spectral_norm` is set, with None
  >   >   returned otherwise.
  >   > * overall\_spectral\_norm\_upper\_bound: Upper bound to the circuit's spectral norm distance, found
  >   >   by summing the spectral norm distances for each synthesized gate. This is also 1/2 an upper bound to
  >   >   the diamond norm distance for noiseless channels.
  >   > * budget\_allocation\_for\_synthesis: List of budget allocation to each synthesized gate.
  >   > * t\_gate\_count\_for\_synthesized\_gates: List of the T-gate counts for each individual synthesized gate.
  >   > * spectral\_norms\_for\_synthesized\_gates: List of the spectral norm distances for each individual
  >   >   synthesized gate.
* **Return type:**
  circuit (CircuitModel)

#### Examples

```python theme={null}
>>> from qiskit.circuit.random import random_clifford_circuit
>>> qc = random_clifford_circuit(5, 10, seed=42)
>>> qc.rz(1.0, 0)
>>> qc.rx(-2.0, 1)
>>> qc.ry(0.5, 4)
>>> synth_qc, info = haiqu.clifford_t_synthesis(qc, total_t_gate_budget=20)
>>> info['input_circuit_properties']['total_num_non_clifford_gates']
3
>>> info['output_circuit_properties']['t_gate_count']
9
>>> info['output_circuit_properties']['overall_spectral_norm_upper_bound']
0.3099627526743576
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.