Python API: Advanced Path-sum
The QuPRS.pathsum subpackage exposes symbolic circuit and Boolean
output-state primitives. This lower-level interface is useful for studying
reduction rules and constructing Path-sums directly. It is distinct from
the recommended high-level verification API.
from QuPRS.pathsum import PathSum, Register, F, support_gate_set
q = Register(2, "q")
circuit = PathSum.QuantumCircuit(q)
circuit = circuit.h(0)
circuit = circuit.cx(0, 1)
assert {"h", "cx"}.issubset(support_gate_set())
Gate methods return a PathSum object; use the returned object instead
of assuming in-place mutation. Gate parameters use the actual source-level
signature and numerical phase conventions described by their implementation.
PathSum
The central object stores a phase polynomial, Boolean output mapping and
summation variables. The methods h, cx, rz, mcx and other
supported gates are attached dynamically from Gate classes. This
reference reads their committed, source-generated core.pyi signatures
and docstrings through Griffe's static stub merge. It does not import
QuPRS or execute gate implementations while rendering the site.
PathSum
Symbolic quantum-circuit Path-sum representation.
Stores the phase polynomial P, Boolean output-state mapping f,
summation variables pathvar, and reduction statistics stats.
See the Path-sum and reduction guide for the mathematical conventions,
including the distinction between Boolean substitutions and phase
coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P
|
Expr
|
SymEngine phase expression. Do not implicitly reduce coefficients modulo two when constructing this value. |
required |
f
|
F
|
Boolean output-state map, with output-bit ordering defined by |
required |
pathvar
|
frozenset[Symbol] | set[Symbol]
|
Set or frozenset of internal SymEngine summation variables. |
frozenset()
|
stats
|
StatisticsManager | None
|
Optional :class: |
None
|
Notes
Gate methods such as h, cx, rz and mcx are installed from
Gate subclasses by attach_gate_methods at import time. Their
source-derived signatures and docstrings are also recorded in the
generated core.pyi stub so that static API documentation and type
tooling can discover them without executing the package.
P
property
_P = P
instance-attribute
_f = f
instance-attribute
_num_qubits = len(f)
instance-attribute
_pathvar = frozenset(pathvar) if isinstance(pathvar, set) else pathvar
instance-attribute
_stats = stats if stats is not None else StatisticsManager()
instance-attribute
bits
property
f
property
num_pathvar
property
num_qubits
property
pathvar
property
regs
property
stats
property
CRk(k, control_qubit, target_qubit, is_bra=False)
Applies the CRK gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
The integer parameter for the controlled rotation. |
required |
control_qubit
|
int | str | Symbol
|
The control qubit. |
required |
target_qubit
|
int | str | Symbol
|
The target qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the CRK gate. |
CRkdg(k, control_qubit, target_qubit, is_bra=False)
Applies the CRKDG gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
The integer parameter for the controlled rotation. |
required |
control_qubit
|
int | str | Symbol
|
The control qubit. |
required |
target_qubit
|
int | str | Symbol
|
The target qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the CRKDG gate. |
QuantumCircuit(*regs, initial_state=None)
staticmethod
Create the identity Path-sum for the supplied registers or width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*regs
|
Register | int
|
A width integer or one or more symbolic Register objects. |
()
|
initial_state
|
Optional[Sequence[object]]
|
Optional indexable sequence of values converted with SymPy's to_anf; scalar bool is not accepted. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
New symbolic circuit, initially with zero phase. |
__eq__(other)
__hash__()
__init__(P, f, pathvar=frozenset(), stats=None)
Initialize a Path-sum from its phase, output map and path variables.
__repr__()
ccx(control_qubit1, control_qubit2, target_qubit, is_bra=False)
Applies the CCX gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control_qubit1
|
int | str | Symbol
|
The first control qubit. |
required |
control_qubit2
|
int | str | Symbol
|
The second control qubit. |
required |
target_qubit
|
int | str | Symbol
|
The target qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the CCX gate. |
ch(control_qubit, target_qubit, is_bra=False)
Applies the CH gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control_qubit
|
int | str | Symbol
|
The control qubit. |
required |
target_qubit
|
int | str | Symbol
|
The target qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the CH gate. |
compose(other_pathsum)
Compose two Path-sums with compatible ordered input/output bits.
Returns a new simplified object, alpha-renaming overlapping summation variables before substitution to avoid variable capture. Raises AssertionError if the bit order does not match.
cp(theta, control_qubit, target_qubit, is_bra=False)
Applies the CP gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle theta in radians. |
required |
control_qubit
|
int | str | Symbol
|
The control qubit. |
required |
target_qubit
|
int | str | Symbol
|
The target qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the CP gate. |
crx(theta, control_qubit, target_qubit, is_bra=False)
Applies the CRX gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle theta in radians. |
required |
control_qubit
|
int | str | Symbol
|
The control qubit. |
required |
target_qubit
|
int | str | Symbol
|
The target qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the CRX gate. |
cry(theta, control_qubit, target_qubit, is_bra=False)
Applies the CRY gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle theta in radians. |
required |
control_qubit
|
int | str | Symbol
|
The control qubit. |
required |
target_qubit
|
int | str | Symbol
|
The target qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the CRY gate. |
crz(theta, control_qubit, target_qubit, is_bra=False)
Applies the CRZ gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle theta in radians. |
required |
control_qubit
|
int | str | Symbol
|
The control qubit. |
required |
target_qubit
|
int | str | Symbol
|
The target qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the CRZ gate. |
cu(theta, phi, lam, gamma, control_qubit, target_qubit, is_bra=False)
Applies the CU gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle theta in radians. |
required |
phi
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle phi in radians. |
required |
lam
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle lambda in radians. |
required |
gamma
|
int | float | Expr | Expr | ParameterExpression
|
The global phase angle in radians. |
required |
control_qubit
|
int | str | Symbol
|
The control qubit. |
required |
target_qubit
|
int | str | Symbol
|
The target qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the CU gate. |
cu1(theta, control_qubit, target_qubit, is_bra=False)
Applies the CU1 gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle theta in radians. |
required |
control_qubit
|
int | str | Symbol
|
The control qubit. |
required |
target_qubit
|
int | str | Symbol
|
The target qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the CU1 gate. |
cu3(theta, phi, lam, control_qubit, target_qubit, is_bra=False)
Applies the CU3 gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle theta in radians. |
required |
phi
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle phi in radians. |
required |
lam
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle lambda in radians. |
required |
control_qubit
|
int | str | Symbol
|
The control qubit. |
required |
target_qubit
|
int | str | Symbol
|
The target qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the CU3 gate. |
cx(control_qubit, target_qubit, is_bra=False)
Applies the CX gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control_qubit
|
int | str | Symbol
|
The control qubit. |
required |
target_qubit
|
int | str | Symbol
|
The target qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the CX gate. |
cy(control_qubit, target_qubit, is_bra=False)
Applies the CY gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control_qubit
|
int | str | Symbol
|
The control qubit. |
required |
target_qubit
|
int | str | Symbol
|
The target qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the CY gate. |
cz(control_qubit, target_qubit, is_bra=False)
Applies the CZ gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control_qubit
|
int | str | Symbol
|
The control qubit. |
required |
target_qubit
|
int | str | Symbol
|
The target qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the CZ gate. |
get_reduction_count(key)
Get the count for a specific reduction rule for this instance.
get_reduction_counts()
Get a copy of all reduction rule counts for this instance.
get_reduction_hitrate()
Calculate the hit rate of reduction rules for this instance.
h(qubit, is_bra=False)
Applies the H gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the H gate. |
id(qubit, is_bra=False)
Applies the ID gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the ID gate. |
is_reduction_enabled()
Check if reduction is enabled for this instance.
load_from_qasm_file(filename, initial_state=None)
staticmethod
load_from_qasm_str(program, initial_state=None)
staticmethod
mcx(*qubits, is_bra=False)
Applies the MCX gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubits
|
int | str | Symbol
|
A list of qubits to which the gate is applied. |
()
|
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the MCX gate. |
p(theta, qubit, is_bra=False)
Applies the P gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle theta in radians. |
required |
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the P gate. |
reduction()
Apply simplification rules to a PathSum object. This logic is extracted from the original PathSum.reduction method.
reset_reduction_counts()
Reset all reduction rule counts for this instance to 0.
rx(theta, qubit, is_bra=False)
Applies the RX gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle theta in radians. |
required |
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the RX gate. |
ry(theta, qubit, is_bra=False)
Applies the RY gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle theta in radians. |
required |
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the RY gate. |
rz(theta, qubit, is_bra=False)
Applies the RZ gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle theta in radians. |
required |
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the RZ gate. |
s(qubit, is_bra=False)
Applies the S gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the S gate. |
sdg(qubit, is_bra=False)
Applies the SDG gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the SDG gate. |
set_reduction_switch(value)
Set the reduction switch for this instance.
swap(qubit1, qubit2, is_bra=False)
Applies the SWAP gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit1
|
int | str | Symbol
|
The first qubit. |
required |
qubit2
|
int | str | Symbol
|
The second qubit. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the SWAP gate. |
sx(qubit, is_bra=False)
Applies the SX gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the SX gate. |
sxdg(qubit, is_bra=False)
Applies the SXDG gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the SXDG gate. |
t(qubit, is_bra=False)
Applies the T gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the T gate. |
tdg(qubit, is_bra=False)
Applies the TDG gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the TDG gate. |
u(theta, phi, lam, qubit, is_bra=False)
Applies the U gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle theta in radians. |
required |
phi
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle phi in radians. |
required |
lam
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle lambda in radians. |
required |
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the U gate. |
u1(theta, qubit, is_bra=False)
Applies the U1 gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle theta in radians. |
required |
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the U1 gate. |
u2(phi, lam, qubit, is_bra=False)
Applies the U2 gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle phi in radians. |
required |
lam
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle lambda in radians. |
required |
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the U2 gate. |
u3(theta, phi, lam, qubit, is_bra=False)
Applies the U3 gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle theta in radians. |
required |
phi
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle phi in radians. |
required |
lam
|
int | float | Expr | Expr | ParameterExpression
|
The rotation angle lambda in radians. |
required |
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the U3 gate. |
x(qubit, is_bra=False)
Applies the X gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the X gate. |
y(qubit, is_bra=False)
Applies the Y gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the Y gate. |
z(qubit, is_bra=False)
Applies the Z gate to the specified qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit
|
int | str | Symbol
|
The qubit to which the gate is applied. |
required |
is_bra
|
bool
|
Whether the input is a bra state. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
PathSum |
PathSum
|
The resulting PathSum object after applying the Z gate. |
Dynamic gate signature sources
The public gate-method names and signatures are built from Gate subclasses'
gate_name, __init__, and apply declarations. The
scripts/generate_stubs.py generator produces core.pyi, and the
documentation CI checks that every source Gate has a matching stub method
and that Griffe can discover it without runtime inspection.
The generated signatures include single-qubit methods such as h and
rz(theta, qubit, is_bra=False), controlled methods such as
cx(control_qubit, target_qubit, is_bra=False), and multi-qubit
methods such as mcx(*qubits, is_bra=False). Some specialized names
are case-sensitive (for example CRk).
Register
Register
Symbolic register identifying the input/output bit positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int | None
|
Register width. Ignored when |
None
|
name
|
str | None
|
Prefix for generated symbols (defaults to |
None
|
bits
|
Optional[Sequence[Symbol]]
|
Optional sequence of existing symbolic bits. |
None
|
Notes
Integer indexing returns the symbol at that register position. This is the Python Path-sum interface, not a Qiskit QuantumRegister.
_bits = tuple(bits) if bits is not None else tuple(se.symbols(f'{name}_:{size}'))
instance-attribute
_name = name
instance-attribute
_repr = f'{self.__class__.__name__}(name={self.name}, size={self.size})'
instance-attribute
_size = size
instance-attribute
name
property
size
property
__getitem__(key)
__init__(size=None, name=None, bits=None)
__len__()
__repr__()
Boolean output mapping: F
F
Boolean output-state map for a symbolic Path-sum.
F[i] identifies the Boolean expression used for output bit i.
Expressions are normalized to algebraic normal form (ANF) when calling
:meth:sub. Boolean substitution uses GF(2) semantics; this does not
imply reducing phase-polynomial coefficients modulo two.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*regs
|
Register
|
Symbolic :class: |
()
|
data
|
dict[str, object] | None
|
Optional mapping from bit names to Boolean expressions. |
None
|
bits
|
Optional[Sequence[str]]
|
Optional explicit output-bit order. |
None
|
Values remain typed as object: update stores arbitrary objects without input validation, while substitution normalizes through SymPy.
_bits = tuple(self._bits)
instance-attribute
_data = self._data
instance-attribute
_regs = tuple(regs)
instance-attribute
bits
property
data
property
regs
property
__eq__(other)
__getitem__(key)
__hash__()
__init__(*regs, data=None, bits=None)
__len__()
__repr__()
items()
Return the live mapping view of output bit names and stored values.
sub(arg1, arg2)
Substitute a Boolean variable or expression and normalize to ANF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg1
|
object
|
Symbol or expression being replaced. |
required |
arg2
|
object
|
Replacement Boolean expression. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
F |
F
|
A new output map; the original object is not modified. |
update(key, value)
Return a new map with one output bit replaced by value.
update_data(data)
Return a new map using data with the current bit ordering.
Boolean output-state expressions and phase-polynomial coefficients belong
to different algebraic domains. A Boolean substitution uses ANF/GF(2)
semantics; do not apply mod 2 to the original phase polynomial when
writing reductions. See Path-sum and reduction for the
Elim, HH, and omega preconditions and ket-preserving identities.
Reduction statistics
StatisticsManager is exposed through PathSum.stats and the
high-level result's Statistics field. Its counters are diagnostic,
not proof certificates; this class is not a top-level QuPRS export.
StatisticsManager
Tracks reductions performed by the Python Path-sum implementation.
Counts include total, Elim, HH, and omega. The hit rate is
(Elim + HH + omega) / total when total > 0; otherwise it is zero.
This is diagnostic instrumentation, not an equivalence certificate.
Instances are available through PathSum.stats and result Statistics.
Notes
The counter keys and this class's location are implementation-facing; prefer the documented result object for high-level verification.
_reduction_enabled = True
instance-attribute
__init__()
__repr__()
get_reduction_count(key)
Get the count for a specific reduction rule.
get_reduction_counts()
Get a copy of all reduction rule counts.
get_reduction_hitrate()
Calculate the hit rate of reduction rules.
increment_reduction_count(key, value=1)
Increase the count for a specific reduction rule.
is_reduction_enabled()
Check if reduction functionality is enabled.
reset_reduction_counts()
Reset all reduction rule counts to 0.
set_reduction_switch(value)
Set the global switch for reduction functionality.
Gate discovery helpers
These helpers are exports of QuPRS.pathsum. They describe what is
currently implemented; they are not a promise that unimplemented gates
will be silently approximated or substituted.
support_gate_set()
Returns a set containing the names of all supported quantum gate methods (e.g., 'h', 'cx').
The names are extracted from the 'gate_name' attribute of each gate class.
get_gates_by_type(gate_type)
Returns a sorted list of gate class names filtered by the specified type.
The type should be one of: 'single', 'two', or 'multi'.
get_all_gates()
Dynamically discovers all Gate subclasses within this package.
This function scans all modules in the 'gates' package, finds classes that inherit from the base 'Gate' class, and returns a map of {gate_name: gate_class}.
Returns:
| Type | Description |
|---|---|
Dict[str, Type[Gate]]
|
A dictionary mapping the gate_name attribute of each gate class |
Dict[str, Type[Gate]]
|
to the class itself. |
list_supported_gates()
Prints all supported quantum gate classes, grouped by their base class type.
API stability
PathSum, Register, F, and gate-discovery functions are exposed
by QuPRS.pathsum.__all__. This does not automatically guarantee
backwards compatibility for every internal implementation detail. For
SolverAdapter and weighted-CNF implementation classes, consult
Weighted model counting; those are not
promoted to stable public Python APIs by this reference.