pytket.circuit.logic_exp¶
For more discussion of classical logic in pytket see the manual section.
Classes and functions for constructing logical expressions over Bit and BitRegister.
- class pytket.circuit.logic_exp.BitLogicExp[source]¶
Expression acting only on Bit or Constant types.
- enum pytket.circuit.logic_exp.BitWiseOp(value)[source]¶
Enum for operations on Bit.
Valid values are as follows:
- AND = <BitWiseOp.AND: '&'>¶
- OR = <BitWiseOp.OR: '|'>¶
- XOR = <BitWiseOp.XOR: '^'>¶
- EQ = <BitWiseOp.EQ: '=='>¶
- NEQ = <BitWiseOp.NEQ: '!='>¶
- NOT = <BitWiseOp.NOT: '~'>¶
- ZERO = <BitWiseOp.ZERO: '0'>¶
- ONE = <BitWiseOp.ONE: '1'>¶
- class pytket.circuit.logic_exp.LogicExp[source]¶
Logical expressions over Bit or BitRegister. Encoded as a tree of expressions
- all_inputs_ordered()[source]¶
- Returns:
All variables involved in expression, in order of first appearance.
- Return type:
list[Variable]
- eval_vals()[source]¶
Attempt to evaluate all sub-expressions; simple constant folding.
- Return type:
Union
[LogicExp
,Bit
,BitRegister
,int
]
- class pytket.circuit.logic_exp.NullaryOp[source]¶
Expression for operation on no arguments (i.e. constant).
- class pytket.circuit.logic_exp.PredicateExp[source]¶
A binary predicate where the arguments are either Bits, BitRegisters, or Constants.
- class pytket.circuit.logic_exp.RegLogicExp[source]¶
Expression acting only on BitRegister or Constant types.
- enum pytket.circuit.logic_exp.RegWiseOp(value)[source]¶
Enum for operations on BitRegister.
Valid values are as follows:
- AND = <RegWiseOp.AND: '&'>¶
- OR = <RegWiseOp.OR: '|'>¶
- XOR = <RegWiseOp.XOR: '^'>¶
- EQ = <RegWiseOp.EQ: '=='>¶
- NEQ = <RegWiseOp.NEQ: '!='>¶
- LT = <RegWiseOp.LT: '<'>¶
- GT = <RegWiseOp.GT: '>'>¶
- LEQ = <RegWiseOp.LEQ: '<='>¶
- GEQ = <RegWiseOp.GEQ: '>='>¶
- ADD = <RegWiseOp.ADD: '+'>¶
- SUB = <RegWiseOp.SUB: '-'>¶
- MUL = <RegWiseOp.MUL: '*'>¶
- DIV = <RegWiseOp.DIV: '/'>¶
- POW = <RegWiseOp.POW: '**'>¶
- LSH = <RegWiseOp.LSH: '<<'>¶
- RSH = <RegWiseOp.RSH: '>>'>¶
- NOT = <RegWiseOp.NOT: '~'>¶
- pytket.circuit.logic_exp.create_bit_logic_exp(op, args)[source]¶
Builds the
LogicExp
corresponding to applying the givenBitWiseOp
to some sequence of bits.- Return type:
- pytket.circuit.logic_exp.create_logic_exp(op, args)[source]¶
Builds the
LogicExp
corresponding to applying the givenBitWiseOp
orRegWiseOp
to some sequence of arguments.- Return type:
- pytket.circuit.logic_exp.create_predicate_exp(op, args)[source]¶
Builds the
LogicExp
corresponding to applying a given comparison predicate to some sequence of arguments.- Return type:
- pytket.circuit.logic_exp.create_reg_logic_exp(op, args)[source]¶
Builds the
LogicExp
corresponding to applying the givenRegWiseOp
to some sequence of registers.- Return type:
- pytket.circuit.logic_exp.filter_by_type(seq, var_type)[source]¶
Return enumeration of seq, with only elements of type var_type.
- pytket.circuit.logic_exp.reg_eq(register, value)[source]¶
Function to express a BitRegister equality predicate, i.e. for a register
r
,(r == 5)
is expressed asreg_eq(r, 5)
- Return type:
- pytket.circuit.logic_exp.reg_geq(register, value)[source]¶
Function to express a BitRegister greater than or equal to predicate, i.e. for a register
r
,(r >= 5)
is expressed asreg_geq(r, 5)
- Return type:
- pytket.circuit.logic_exp.reg_gt(register, value)[source]¶
Function to express a BitRegister greater than predicate, i.e. for a register
r
,(r > 5)
is expressed asreg_gt(r, 5)
- Return type:
- pytket.circuit.logic_exp.reg_leq(register, value)[source]¶
Function to express a BitRegister less than or equal to predicate, i.e. for a register
r
,(r <= 5)
is expressed asreg_leq(r, 5)
- Return type:
- pytket.circuit.logic_exp.reg_lt(register, value)[source]¶
Function to express a BitRegister less than predicate, i.e. for a register
r
,(r < 5)
is expressed asreg_lt(r, 5)
- Return type:
- pytket.circuit.logic_exp.reg_neq(register, value)[source]¶
Function to express a BitRegister inequality predicate, i.e. for a register
r
,(r != 5)
is expressed asreg_neq(r, 5)
- Return type:
pytket.circuit.add_condition¶
Enable adding of gates with conditions on Bit or BitRegister expressions.
pytket.circuit.clexpr¶
- pytket.circuit.clexpr.check_register_alignments(circ)[source]¶
Check whether all ClExprOp operations in the circuit are register-aligned.
This means that all register variables and outputs occurring in ClExprOp comprise whole registers with the bits in the correct order.
pytket.circuit.decompose_classical¶
Functions for decomposing Circuits containing classical expressions in to primitive logical operations.
- exception pytket.circuit.decompose_classical.DecomposeClassicalError[source]¶
Error with decomposing classical operations.
- class pytket.circuit.decompose_classical.BitHeap(_reg_name='tk_SCRATCH_BIT')[source]¶
Heap of temporary Bits.
- class pytket.circuit.decompose_classical.RegHeap(_reg_name_base='tk_SCRATCH_BITREG')[source]¶
Heap of temporary BitRegisters.