terms
Term-family modules for compiled scalar graphs.
Each compiled ZX scalar is the product of four term families plus a global phase and a floatfactor. This module defines the four families as equinox.Module records, bundles the shared phase tables, and gives each family an evaluate method that turns a batch of binary parameter values into an ExactScalarArray.
Downstream, compile.py builds instances of these classes from pyzx_param scalars, and evaluate.py orchestrates the products.
HalfPiPhases
Bases: Module
flowchart TD
tsim.compile.terms.HalfPiPhases[HalfPiPhases]
click tsim.compile.terms.HalfPiPhases href "" "tsim.compile.terms.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
evaluate(param_vals: Array) -> ExactScalarArray
Evaluate ω^(Σ coeffs · parity) per graph, batched over param_vals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param_vals | Array | Binary parameter values, shape | required |
Returns:
| Type | Description |
|---|---|
ExactScalarArray |
|
Source code in src/tsim/compile/terms.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
NodePhases
Bases: Module
flowchart TD
tsim.compile.terms.NodePhases[NodePhases]
click tsim.compile.terms.NodePhases href "" "tsim.compile.terms.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
evaluate(param_vals: Array) -> ExactScalarArray
Evaluate Π (1 + ω^(4·parity + phase)) per graph, batched over param_vals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param_vals | Array | Binary parameter values, shape | required |
Returns:
| Type | Description |
|---|---|
ExactScalarArray |
|
Source code in src/tsim/compile/terms.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
PhasePairs
Bases: Module
flowchart TD
tsim.compile.terms.PhasePairs[PhasePairs]
click tsim.compile.terms.PhasePairs href "" "tsim.compile.terms.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
evaluate(param_vals: Array) -> ExactScalarArray
Evaluate Π (1 + ω^α + ω^β - ω^(α+β)) per graph, batched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param_vals | Array | Binary parameter values, shape | required |
Returns:
| Type | Description |
|---|---|
ExactScalarArray |
|
Source code in src/tsim/compile/terms.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
PiProducts
Bases: Module
flowchart TD
tsim.compile.terms.PiProducts[PiProducts]
click tsim.compile.terms.PiProducts href "" "tsim.compile.terms.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
evaluate(param_vals: Array) -> ExactScalarArray
Evaluate Π (-1)^(ψ·φ) per graph as a real ±1 exact scalar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param_vals | Array | Binary parameter values, shape | required |
Returns:
| Type | Description |
|---|---|
ExactScalarArray |
|
ExactScalarArray | in {+1, -1} represented exactly. |
Source code in src/tsim/compile/terms.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
ScalarPrefactor
Bases: Module
flowchart TD
tsim.compile.terms.ScalarPrefactor[ScalarPrefactor]
click tsim.compile.terms.ScalarPrefactor href "" "tsim.compile.terms.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.