qdk_chemistry.algorithms.term_grouper package
Term-grouper algorithms for QubitOperator.
A term grouper takes a QubitOperator and
returns a new one with a populated
term_partition that downstream
algorithms can exploit.
Example
>>> from qdk_chemistry.algorithms import registry
>>> grouper = registry.create("term_grouper", "qubit_wise_commuting")
>>> grouped = grouper.run(my_hamiltonian)
>>> grouped.term_partition # FlatPartition with strategy="qubit_wise_commuting"
- class qdk_chemistry.algorithms.term_grouper.FullCommutingTermGrouper
Bases:
TermGrouperGroup terms by full Pauli commutation (
[P_i, P_j] = 0).The resulting
FlatPartitionstores aQubitOperatorpartition where every pair of terms in the same group commutes globally. Useful for Trotter-style decompositions, which can exponentiate a commuting block as a single ordered product without splitting error.
- class qdk_chemistry.algorithms.term_grouper.IdentityTermGrouper
Bases:
TermGrouperTrivial grouper — every term is placed in its own single-element group.
Useful to clear an existing
term_partitionwhile still passing through the standardterm_grouperinterface, or to disable downstream group-aware optimisation in a controlled way.
- class qdk_chemistry.algorithms.term_grouper.QubitWiseCommutingTermGrouper
Bases:
TermGrouperGroup terms by qubit-wise commutation.
Two labels qubit-wise commute when, on every qubit position, the two single-qubit Paulis individually commute (i.e. one is identity or both are equal). All members of a group can be measured in a single basis, which is the property exploited by
QdkExpectationEstimatorfor measurement-cost reduction.
- class qdk_chemistry.algorithms.term_grouper.TermGrouper
Bases:
AlgorithmAbstract base class for algorithms that partition Hamiltonian terms.
A
TermGrouperconsumes aQubitOperatorand returns a newQubitOperatorwhoseterm_partitionis populated with the grouping computed by the strategy.Subclasses implement
_run_impl, which must return a newQubitOperator(the input must not be mutated).- __init__()
Initialise the term grouper with default settings.
- class qdk_chemistry.algorithms.term_grouper.TermGrouperFactory
Bases:
AlgorithmFactoryFactory for
TermGrouperinstances.
- class qdk_chemistry.algorithms.term_grouper.TermGrouperSettings
Bases:
SettingsSettings for term-grouper algorithms.
- __init__()
Initialise default term-grouper settings (currently empty).
- class qdk_chemistry.algorithms.term_grouper.VacuumAnnihilatingTermGrouper
Bases:
TermGrouperGroup Pauli terms whose weighted amplitudes cancel on \(|0\ldots0\rangle\).
Only terms sharing a flipped-qubit set reach the same basis state \(|b_F\rangle\), so they are the only ones whose amplitudes can cancel. Each set has to satisfy \(\sum_j c_j\, P_j\, |0\ldots0\rangle = 0\) to within
tolerance, otherwise grouping fails with aValueError. A certified set is then cut wherever its running sum vanishes exactly, so every group but the last cancels on its own and the last carries the tolerated residual. Diagonal (\(I\)/\(Z\)) strings only phase the vacuum, which a consumer can correct for, so they form one group whose sum is left unconstrained.Groups hold a single \(Y\)-count parity, which makes their members commute: two strings sharing a flipped-qubit set disagree only inside it, and the number of such positions has parity \(n_Y^{(a)} + n_Y^{(b)} \bmod 2\). No cancellation is lost, since with real coefficients the even-parity terms contribute \(\pm 1\) and the odd-parity ones \(\pm i\), so the two sub-sums are the real and imaginary parts of the total.
The motivating case is fermionic chemistry, where each excitation annihilates the all-zero reference only through the weighted sum of its Pauli strings, which is the ordering the
ControlledSwapPauliSequenceMapperrequires.- __init__()
Initialise the VacuumAnnihilatingTermGrouper.
- class qdk_chemistry.algorithms.term_grouper.VacuumAnnihilatingTermGrouperSettings
Bases:
TermGrouperSettingsSettings for the
VacuumAnnihilatingTermGrouper.- tolerance
Absolute tolerance on the vacuum amplitude of a flipped-qubit set.
- __init__()
Initialise the settings for VacuumAnnihilatingTermGrouper.