pdft.circuit.CircuitCode#

class pdft.circuit.CircuitCode(program, inverse=False, slices=True, merge_diagonals=True)[source]#

Bases: object

code(*tensors, pic): a program applied to pic of shape (2,) * (m + n).

The callable a basis keeps as code and inv_code. The qubit axes are the first m + n; for a stack of images use apply_program. It compares and hashes by its fields (program, direction, arithmetic), so two bases with the same circuit and arithmetic share one compiled applier and have equal pytree structures.

Two options change the arithmetic and not the operator, and both are on by default: slices computes the one-qubit gates without a contraction (see _one_qubit), and merge_diagonals applies each run of CP gates as one diagonal (see _walk). With both off a code runs the arithmetic of pdft 0.3.0, and on a CPU gives its numbers bit for bit. To get that on a basis, construct it with code=dataclasses.replace(basis.code, slices=False, merge_diagonals=False) (for a BlockedBasis, construct its inner basis so); the inverse code follows.

Parameters:
__init__(program, inverse=False, slices=True, merge_diagonals=True)#
Parameters:
Return type:

None

Methods

__init__(program[, inverse, slices, ...])

Attributes

program: Program#
inverse: bool = False#
slices: bool = True#
merge_diagonals: bool = True#