Trotterization¶
Choose the number of Trotter steps for a Pauli Hamiltonian, an evolution time and an operator-norm error budget, evaluate the product-formula error bound behind that choice, and build the product-formula circuit. Import the functions from nwqlib.subroutines.trotterization.
from qiskit.quantum_info import SparsePauliOp
from nwqlib.subroutines.trotterization import (
build_trotter_evolution_circuit,
select_trotter_step_count,
)
H = SparsePauliOp(["XI", "ZZ"], [0.5, 0.5])
selection = select_trotter_step_count(H, time=2.0, error_budget=0.01, order=2)
print(selection.step_count, round(selection.bound_value, 10))
circuit = build_trotter_evolution_circuit(H, selection)
print(selection.synthesis_method, circuit.num_qubits)
8 0.0078125
suzuki_trotter 2
The second-order coefficient of this H is 1/16, and 8 is the smallest r with (1/16) * 2**3 / r**2 <= 0.01.
The error bound¶
- The first-order bound is Proposition 9, Eq. (120), and the second-order bound is Proposition 10, Eq. (121), of Childs, Su, Tran, Wiebe and Zhu, Phys. Rev. X 11, 011020 (2021), doi:10.1103/PhysRevX.11.011020. One application of the order-
oformula obeysbound(t) = W_up * t**(o + 1). - For an evolution at one supplied time, the step count is the smallest one allowed by the rule of their Sec. V B: with
rsteps the total is at mostr * bound(t / r). - The bound expands each commutator norm over Pauli strings by the triangle inequality, with
||[P, Q]|| = 2when P and Q anticommute and||[P, [Q, R]]|| = 4when both commutators are nonzero. It is never smaller than the exact tail-sum norms of those equations. At second order the functions use the full Pauli-triangle expression by default, andbound_variant="relaxed_prefix"selects the suffix relaxation, which needs pair tests only, has a potentially larger coefficient and can select more steps. - The prefactor
W_upis evaluated with scaled binary64 upper products and sums followed by rational rescaling, so it bounds the selected expression and can exceed it. The bound and the step inversion use exact rationals formed fromW_upand the binary64 time and budget, so no intermediate rounds to zero or overflows. The selected count is minimal forW_up, and a published bound is rounded upward to binary64, which keeps a nonzero bound positive and a selected bound at most the budget.
Functions and records¶
select_trotter_step_count ¶
select_trotter_step_count(hamiltonian: SparsePauliOp, *, time: float, error_budget: float, order: int = 1, bound_variant: str = 'exact_census', max_work: int = DEFAULT_CENSUS_MAX_WORK, max_bytes: int = DEFAULT_MAX_BYTES) -> TrotterStepSelection
Return the smallest Trotter step count whose error bound meets an error budget.
Applies the rule of [CSTWZ] doi:10.1103/PhysRevX.11.011020, Sec. V B:
with r steps the total additive
error is at most r * bound(time / r) (triangle inequality over the
unitary steps), and the smallest admissible r follows in closed
form because bound(t) = W_up * t**(order + 1):
- order 1: total
= W_up * t^2 / r, sor = max(1, ceil(t^2 * W_up / epsilon)); - order 2: total
= W_up * t^3 / r^2, sor = max(1, ceil(sqrt(ceil(t^3 * W_up / epsilon)))).
W_up is the outward upper bound of the bound_variant expression
(full exact_census by default, relaxed_prefix on request), so
the count is minimal for W_up, not for the exact triangle coefficient.
With the relaxed expression at order 2,
r_exact <= r_rel <= ceil(alpha * r_exact) for
alpha = sqrt(W_2,rel / W_2) in exact arithmetic.
The count of anticommuting Pauli pairs and triples checks its work and
byte limits (max_work, max_bytes) before converting labels or
building its index tables, and a requested expression that does not fit
raises before the stage that would exceed them.
Parameters:
-
hamiltonian(SparsePauliOp) –H = sum_j c_j P_jin the term order of the product formula. Coefficients must be finite and real (an imaginary part of at most 1e-12 in absolute value is accepted), and identity terms are rejected: remove them and keep their global phaseexp(-i t c)yourself. -
time(float) –Evolution time
t. -
error_budget(float) –Allowed operator-norm error
epsilonof the whole evolution. -
order(int, default:1) –Default
1. Product-formula order, 1 (Lie-Trotter) or 2 (second-order Suzuki). -
bound_variant(str, default:'exact_census') –Default
"exact_census", the full Pauli-triangle expression. At order 2,"relaxed_prefix"selects the suffix relaxation, which needs pair tests only and can give a larger bound. -
max_work(int, default:DEFAULT_CENSUS_MAX_WORK) –Default
1_000_000_000. Work limit of the pair and triple tests. -
max_bytes(int, default:DEFAULT_MAX_BYTES) –Default 10 GB (decimal,
10_000_000_000bytes). Byte limit of the tests and their index tables.
Returns:
-
selection(TrotterStepSelection) –selection.step_countis the step count, andselection.bound_valueis the certified total bound at that count (<= error_budget).selection.synthesis_methodnames the Qiskit product formula ("lie_trotter"or"suzuki_trotter").
Examples:
For H = X + Z the second-order coefficient is
||[Z, [Z, X]]||/12 + ||[X, [X, Z]]||/24 = 1/2, so at t = 1 and
epsilon = 0.01 the smallest r with (1/2)/r**2 <= 0.01 is 8:
>>> from qiskit.quantum_info import SparsePauliOp
>>> from nwqlib.subroutines.trotterization import (
... select_trotter_step_count)
>>> H = SparsePauliOp(["X", "Z"], [1.0, 1.0])
>>> selection = select_trotter_step_count(
... H, time=1.0, error_budget=0.01, order=2)
>>> print(selection.step_count, round(selection.bound_value, 10))
8 0.0078125
build_trotter_evolution_circuit ¶
build_trotter_evolution_circuit(hamiltonian: SparsePauliOp, selection: TrotterStepSelection) -> QuantumCircuit
Build the product-formula circuit S_order(time / step_count)**step_count of a step-count selection.
Validates hamiltonian (the operator selection was computed for)
and builds the circuit with Qiskit's product-formula synthesis
(LieTrotter or SuzukiTrotter, as selection.synthesis_method
names) repeated step_count times. The summands are applied in term
order, matching the ordering the recorded bounds are stated for.
Parameters:
-
hamiltonian(SparsePauliOp) –The Hamiltonian the selection was computed for.
-
selection(TrotterStepSelection) –Output of
select_trotter_step_count.
Returns:
-
circuit(QuantumCircuit) –The evolution circuit on
hamiltonian.num_qubitsqubits.
trotter_bound_coefficient ¶
trotter_bound_coefficient(hamiltonian: SparsePauliOp, *, order: int = 1, bound_variant: str = 'exact_census', max_work: int = DEFAULT_CENSUS_MAX_WORK, max_bytes: int = DEFAULT_MAX_BYTES) -> float
Return the time-independent prefactor W_up of the Trotter error bound W_up * t**(order + 1).
W_up is an outward upper bound on the Pauli-triangle expression
selected by bound_variant, which bounds the commutator sum of [CSTWZ]
doi:10.1103/PhysRevX.11.011020, Prop. 9 (order=1) or Prop. 10
(order=2), so one product-formula
application obeys bound(t) = W_up * t**(order + 1) and the Sec. V B
r-step total is W_up * t**(order + 1) / r**order. Exposed for
direct evaluation without dense matrices. W_up can exceed the exact
triangle coefficient, and it is returned rounded upward to binary64.
The count of anticommuting Pauli pairs and triples checks its work and
byte limits (max_work, max_bytes) before converting labels or
building its index tables, and a requested expression that does not fit
raises before the stage that would exceed them.
Parameters:
-
hamiltonian(SparsePauliOp) –H = sum_j c_j P_jin the term order of the product formula. Coefficients must be finite and real (an imaginary part of at most 1e-12 in absolute value is accepted), and identity terms are rejected: remove them and keep their global phaseexp(-i t c)yourself. -
order(int, default:1) –Default
1. Product-formula order, 1 (Lie-Trotter) or 2 (second-order Suzuki). -
bound_variant(str, default:'exact_census') –Default
"exact_census", the full Pauli-triangle expression. At order 2,"relaxed_prefix"selects the suffix relaxation, which needs pair tests only and can give a larger bound. -
max_work(int, default:DEFAULT_CENSUS_MAX_WORK) –Default
1_000_000_000. Work limit of the pair and triple tests. -
max_bytes(int, default:DEFAULT_MAX_BYTES) –Default 10 GB (decimal,
10_000_000_000bytes). Byte limit of the tests and their index tables.
Returns:
-
coefficient(float) –W_up, rounded upward to binary64.
Raises:
-
ValueError–W_up exceeds the largest binary64 number, a limit is not a positive integer, or the requested pair and triple tests do not fit
max_workandmax_bytes.
trotter_error_bound ¶
trotter_error_bound(hamiltonian: SparsePauliOp, *, time: float, order: int = 1, max_work: int = DEFAULT_CENSUS_MAX_WORK, max_bytes: int = DEFAULT_MAX_BYTES) -> float
Return an upper bound on the error ||S_order(time) - exp(-i time H)|| of one product-formula application.
Evaluates ||S_order(time) - exp(-i * time * H)|| bounds in spectral
norm: [CSTWZ] doi:10.1103/PhysRevX.11.011020, Prop. 9, Eq. (120) at
order=1 (Lie-Trotter) and
Prop. 10, Eq. (121) at order=2 (Suzuki), with the commutator norms
upper-bounded by the outward full Pauli-triangle coefficient. The summand
order is hamiltonian's term order.
At order two, evaluate_trotter_bound(..., steps=1,
bound_variant="relaxed_prefix") gives the relaxed bound.
The count of anticommuting Pauli pairs and triples checks its work and
byte limits (max_work, max_bytes) before converting labels or
building its index tables, and a requested expression that does not fit
raises before the stage that would exceed them.
Parameters:
-
hamiltonian(SparsePauliOp) –H = sum_j c_j P_jwith finite real coefficients and no identity term, in the term order of the product formula, as forselect_trotter_step_count. -
time(float) –Time of the one application.
-
order(int, default:1) –Default
1. Product-formula order, 1 (Lie-Trotter) or 2 (second-order Suzuki). -
max_work(int, default:DEFAULT_CENSUS_MAX_WORK) –Default
1_000_000_000. Work limit of the pair and triple tests. -
max_bytes(int, default:DEFAULT_MAX_BYTES) –Default 10 GB (decimal,
10_000_000_000bytes). Byte limit of the tests and their index tables.
Returns:
-
bound(float) –The bound, rounded upward to binary64.
evaluate_trotter_bound ¶
evaluate_trotter_bound(hamiltonian: SparsePauliOp, *, time: float, steps: int, order: int = 1, bound_variant: str = 'exact_census', max_work: int = DEFAULT_CENSUS_MAX_WORK, max_bytes: int = DEFAULT_MAX_BYTES) -> float
Return the error bound W_up * time**(order + 1) / steps**order of a product formula with a given step count.
For r=steps, the [CSTWZ] (doi:10.1103/PhysRevX.11.011020)
triangle-inequality composition gives
r * bound(time / r) = W_up * time**(order + 1) / r**order with the
outward coefficient W_up of the bound_variant expression. At fixed
steps the relaxed expression changes no step count, only a possibly
larger certified bound.
The count of anticommuting Pauli pairs and triples checks its work and
byte limits (max_work, max_bytes) before converting labels or
building its index tables, and a requested expression that does not fit
raises before the stage that would exceed them.
Parameters:
-
hamiltonian(SparsePauliOp) –H = sum_j c_j P_jwith finite real coefficients and no identity term, in the term order of the product formula, as forselect_trotter_step_count. -
time(float) –Total evolution time.
-
steps(int) –Positive number of product-formula steps.
-
order(int, default:1) –Default
1. Product-formula order, 1 (Lie-Trotter) or 2 (second-order Suzuki). -
bound_variant(str, default:'exact_census') –Default
"exact_census", or"relaxed_prefix"for the second-order suffix relaxation. -
max_work(int, default:DEFAULT_CENSUS_MAX_WORK) –Default
1_000_000_000. Work limit of the pair and triple tests. -
max_bytes(int, default:DEFAULT_MAX_BYTES) –Default 10 GB (decimal,
10_000_000_000bytes). Byte limit of the tests and their index tables.
Returns:
-
bound(float) –The total bound, rounded upward to binary64.
TrotterStepSelection ¶
TrotterStepSelection(*, formula_order: int, evolution_time: float, error_budget: float, bound_value: float, step_count: int, pauli_term_count: int = 0, pair_commutation_checks: int = 0, nested_commutation_checks: int = 0, bound_variant: str, coefficient_arithmetic: str, common_tau: float | None = None, common_g: int | None = None, common_m: int | None = None, common_step_time: float | None = None, common_prefix_steps: tuple[tuple[int, int], ...] | None = None, common_power_allowances: tuple[tuple[int, float], ...] | None = None, common_recheck_outcome: str | None = None, common_prefix_bounds: tuple[tuple[int, float], ...] | None = None)
The step count chosen for one product-formula error budget, with its error bound.
select_trotter_step_count
returns it. The answer is step_count, and bound_value is its
certified error bound. The fields below are read-only.
Fields mirror the [CSTWZ] (doi:10.1103/PhysRevX.11.011020) quantities:
bound_value is the certified
total additive Trotter error bound step_count * bound(evolution_time /
step_count) at the selected step count (at most error_budget), with
the per-application bound and the smallest-r arithmetic recorded as the
bound_formula and step_formula source strings.
A common selection binds one ordered step to every requested power by
its integer grid and cumulative counts. Its exact targets are derived
from the stored time unit, and its acceptance records the completed
emitted-parameter recheck at every prefix (select_common_step). The
common_* fields are None ("not recorded") on an independent
selection. The maximum target time p_max*val(common_tau) and each
represented prefix time r(p)*val(common_step_time) are derived, not
stored. Validation derives g from the positive powers, requires every
power to be divisible by it and checks r(p) = (p/g)*m. The all-zero
schedule has no g, m or step and no common selection.
Attributes:
-
formula_order(int) –Selected Lie order 1 or symmetric Suzuki order 2. On a common selection: order of the shared ordered product-formula step. Common QPE trajectories use the symmetric second-order Suzuki formula.
-
evolution_time(float) –Total evolution time t > 0 of the product formula. On a common selection: binary64 display of the largest common-grid target time, whose exact value is defined by the maximum power and stored tau.
-
error_budget(float) –Requested operator-error allowance for this evolution. On a common selection: effective product-formula allowance for the full common trajectory after the other structural contributions are reserved at every queried power, that is
min_(p>0) (epsilon_p-P_p-T_p-I_p-A_p)*r_max/r_prounded downward to binary64. -
bound_value(float) –Upward-rounded total operator-error bound at step_count, computed from the supplied upper coefficient and evolution_time. On a common selection: upward product-formula bound
W_up*r_max*abs(val(h_hat))**3for the actually emitted common step. -
step_count(int) –Smallest positive integer admitted by the supplied upper coefficient and remaining error_budget. On a common selection: number r(p_max) of shared steps through the last requested power. This is a sufficient common-grid count and need not be the independently smallest count for that power.
-
pauli_term_count(int) –Kept nonidentity terms of this node or Hamiltonian.
-
pair_commutation_checks(int) –New logical pair tests incurred by this selection, zero when the coefficient or structure was reused.
-
nested_commutation_checks(int) –New logical nested tests incurred by this selection, zero for relaxed_prefix or reused structure.
-
bound_variant(str) –Selected Pauli-triangle expression, "exact_census" for the full pair/triple indicator structure or "relaxed_prefix" for the second-order suffix relaxation. Order 1 uses "exact_census".
-
coefficient_arithmetic(str) –Numerical evaluation used for the supplied coefficient, "outward_float64_scaled" for scaled binary64 upper products and sums with rational rescaling.
-
common_tau(float | None) –Stored finite positive binary64 time unit. The exact target time at integer power p is p times its represented value.
-
common_g(int | None) –Greatest common divisor of the positive requested integer powers. It identifies the exact target-time grid.
-
common_m(int | None) –Positive integer subdivisions of g times the represented time unit. The ideal common step is g*val(tau)/m.
-
common_step_time(float | None) –Stored binary64 parameter h_hat used by the emitted shared step. Its represented value can differ from the ideal rational step.
-
common_prefix_steps(tuple[tuple[int, int], ...] | None) –Integer cumulative counts r(p)=(p/g)*m at each requested power, with r(0)=0, as
(power, count)pairs. Execution between adjacent points uses the difference of these counts. -
common_power_allowances(tuple[tuple[int, float], ...] | None) –Per-power structural operator-error allowances used by the emitted-step recheck, as
(power, allowance)pairs. Stored binary64 allowances are interpreted as exact represented values for comparison. -
common_recheck_outcome(str | None) –Outcome of comparing every complete emitted-prefix subtotal with its corresponding allowance. Accepted common selections have all powers passed. An absent outcome means the recheck was not recorded.
-
common_prefix_bounds(tuple[tuple[int, float], ...] | None) –Upward-published values of the exact pruning, product-formula, time-displacement, identity-phase and leaf-angle subtotals for the actual emitted prefixes, as
(power, bound)pairs.
bound_formula ¶
bound_formula: str
Selected coefficient expression, source theorem and inequality.
A common selection names the emitted-step composition.
step_formula ¶
step_formula: str
Integer inversion of W_upabs(t)(order+1)/r*order against the remaining error budget.
synthesis_method ¶
synthesis_method: str
Qiskit product formula used for the circuit: "lie_trotter" at order 1, "suzuki_trotter" at order 2.
bound_method ¶
bound_method: str
Name of the bound, "pauli_triangle": commutator norms bounded by the Pauli triangle inequality.
bound_value_status ¶
bound_value_status: str
Meaning of bound_value, "structural_upper_bound": an upper bound on the product-formula operator error.
Cost and limits¶
- A coefficient or fixed-step bound above the largest binary64 number raises
ValueError. - The keyword arguments
max_work(default 1,000,000,000) andmax_bytes(default 10,000,000,000) limit the tests of anticommuting Pauli pairs and triples. The pair stage is checked before label conversion. The requested expression is checked again with the actual pair count before the nested tests or the contraction. - The full second-order expression stores three intp indices per surviving triple and can require cubic storage in the number of terms. The contraction block limits coefficient-reduction scratch and does not limit the stored index count. If the requested expression does not fit, the function raises before the stage that would exceed the limits.
- A refusal names the failed stage and reports sufficient complete limits for the requested order and variant. Its block-one byte value is a checked candidate, not a minimum over all block sizes, and a byte-fit failure is reported only when no checked candidate fits the current byte limit.
- An order-two refusal of the full expression also names
bound_variant="relaxed_prefix"as an explicit alternative, which is checked against the same limits.
Common time grid of QPE powers¶
A QPE trajectory on a common time grid selects one step for all power positions and checks the emitted step against the structural allowance of every prefix. The QPE implementation map lists where controlled product-formula powers use these bounds.
val(tau)denotes the exact real value of the stored binary64 time unit, and a nonnegative integer powerptargets the timep * val(tau).- If
his the exact real value of the emitted binary64 step andris its cumulative count, the second-order product-formula bound isr * W * abs(h)**3. The discrepancy betweenr * hand the target contributes a separate operator bound. - A complete controlled-power bound also includes pruning and the applicable identity-phase and rotation-angle formation terms. The
common_*fields ofTrotterStepSelectionrecord this selection.
Proposition numbering¶
Unless marked as arXiv:1912.08854v3, every proposition, equation and section number on this page and in the docstrings follows the Phys. Rev. X version, doi:10.1103/PhysRevX.11.011020. The arXiv:1912.08854v3 preprint, titled "A Theory of Trotter Error", numbers the same results Proposition 15/Eq. (145) (p. 38), Proposition 16/Eq. (152) (p. 39) and Sec. 5.2 (p. 40).