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

# compile

> Compilation of ZX graphs into JAX-compatible data structures.

## class `CompiledScalarGraphs`

```python theme={null}
CompiledScalarGraphs()
```

JAX-compatible compiled representation of a list of scalar ZX graphs.

The scalar for each graph is a product of four term families, multiplied by
a per-graph `ScalarPrefactor` (global phase, floatfactor, `2^power2`,
optional approximate complex floatfactor). All arrays are static-shaped so
the whole struct can be traced under `jax.jit`.

## class `HalfPiPhases`

```python theme={null}
HalfPiPhases()
```

Sum of `exp(i·j·π·⊕params / 2)` terms with `j ∈ \{1, 3\}`.

Terms sharing a parameter bitstring have been combined to a single stored
coefficient `j' ∈ \{1, 2, 3\}` (see `_compile_halfpi_phases`). Coefficients
are stored in eighth-turn units — i.e. as `2·j'` — so the evaluator can
reuse the `ω = e^(iπ/4)` phase table.

Padded slots use `0` (the additive identity for phase sums), so padded
entries contribute nothing to the summed exponent.

Shapes are `(num_graphs, max_terms)` except `params` which is
`(num_graphs, max_terms, n_params)`.

### `evaluate`

```python theme={null}
evaluate(param_vals: Array) -> ExactScalarArray
```

Evaluate ω^(Σ coeffs · parity) per graph, batched over param\_vals.

**Parameters:**

* `param_vals` (`Array`) — Binary parameter values, shape `(batch, n_params)`.

**Returns:**

* `ExactScalarArray` — `ExactScalarArray` of shape `(batch, num_graphs)`.

## class `NodePhases`

```python theme={null}
NodePhases()
```

Product of `1 + exp(i·(α + ⊕params)·π)` terms, one factor per stored term.

Padded slots use `0` for both `phases` and `params`; the evaluator masks
padded slots to the multiplicative identity using `counts`.

Shapes are `(num_graphs, max_terms)` except `params` which is
`(num_graphs, max_terms, n_params)`.

### `evaluate`

```python theme={null}
evaluate(param_vals: Array) -> ExactScalarArray
```

Evaluate Π (1 + ω^(4·parity + phase)) per graph, batched over param\_vals.

**Parameters:**

* `param_vals` (`Array`) — Binary parameter values, shape `(batch, n_params)`.

**Returns:**

* `ExactScalarArray` — `ExactScalarArray` of shape `(batch, num_graphs)`.

## class `PhasePairs`

```python theme={null}
PhasePairs()
```

Product of `1 + e^(iα) + e^(iβ) − e^(i(α+β))` terms.

Each of `α` and `β` combines a constant phase with a parameter parity.
Padded slots use `0` and are masked to the multiplicative identity using
`counts`.

Shapes are `(num_graphs, max_terms)` except `*_params` which are
`(num_graphs, max_terms, n_params)`.

### `evaluate`

```python theme={null}
evaluate(param_vals: Array) -> ExactScalarArray
```

Evaluate Π (1 + ω^α + ω^β - ω^(α+β)) per graph, batched.

**Parameters:**

* `param_vals` (`Array`) — Binary parameter values, shape `(batch, n_params)`.

**Returns:**

* `ExactScalarArray` — `ExactScalarArray` of shape `(batch, num_graphs)`.

## class `PiProducts`

```python theme={null}
PiProducts()
```

Product of `(-1)^(ψ · φ)` terms, with ψ and φ each a parity expression.

Each side is encoded as a constant bit plus a parameter bitmask. Padded slots
use `0` everywhere; a padded term contributes `(-1)^0 = 1` to the product.

Shapes are `(num_graphs, max_terms)` except `*_params` which are
`(num_graphs, max_terms, n_params)`.

### `evaluate`

```python theme={null}
evaluate(param_vals: Array) -> ExactScalarArray
```

Evaluate Π (-1)^(ψ·φ) per graph as a real ±1 exact scalar.

**Parameters:**

* `param_vals` (`Array`) — Binary parameter values, shape `(batch, n_params)`.

**Returns:**

* `ExactScalarArray` — `ExactScalarArray` of shape `(batch, num_graphs)`, with values
* `ExactScalarArray` — in \{+1, -1} represented exactly.

## class `ScalarPrefactor`

```python theme={null}
ScalarPrefactor()
```

Per-graph static scalar prefactor — independent of parameter values.

Each graph's amplitude is the product of the four term families times the
prefactor `ω^phase_index · floatfactor · 2^power2`, with an additional
complex `approximate_floatfactor` multiplied in when any graph's phase
had a denominator outside `\{1, 2, 4\}` and was folded into float form.

This class is pure data; the final fold-in with the term-family product
(which requires branching on `has_approximate_floatfactors`) lives in
`evaluate.py`.

## `compile_scalar_graphs`

```python theme={null}
compile_scalar_graphs(g_list: list[BaseGraph], params: list[str]) -> CompiledScalarGraphs
```

Compile ZX-graph list into JAX-compatible structure for fast evaluation.

**Parameters:**

* `g_list` (`list[BaseGraph]`) — List of ZX-graphs to compile (must be scalar graphs with no vertices)
* `params` (`list[str]`) — List of parameter names used by this circuit. Each parameter will correspond to columns in the jax.Arrays of the compiled circuit.

**Returns:**

* `CompiledScalarGraphs` — CompiledScalarGraphs with all data in static-shaped JAX arrays


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