circkit.circuit¶
- class circkit.circuit.BaseCircuit(*args, **kwargs)¶
Bases:
objectBase circuit class, defining all the “magic” of
Operation`s and :class:.Node`s.Responsible for tracking
Operationclasses, dynamically subclassingOperationandNodeclasses, and copying/pickling.- class Operations¶
Bases:
objectContainer of Operation classes. Apriori is not linked to any Circuit class, can be reused/inherited from.
- class Node(operation, incoming)¶
Bases:
objectNode in a circuit.
- __init__(operation, incoming)¶
- is_OUTPUT()¶
Returns whether this node is an output node in its circuit.
- reapply(*incoming, circuit=None, inherit_info=True, auto_output=False)¶
Apply the same operation to new incoming nodes/values in th. # AU: auto_output option? (outputs in new circuit if is output here)
- siblings_by_outgoing(node=None)¶
Find the siblings of current by outgoing nodes (or by the single @node node)
- class circkit.circuit.Circuit(*args, **kwargs)¶
Bases:
BaseCircuitMain Circuit class, includes skeleton structure and common methods, and the basic INPUT, CONST, GET nodes.
- class Operations¶
Bases:
Operations- class INPUT(*values, **kvalues)¶
Bases:
OperationInput node. Parameters:
name (str): name of the input
- __init__(name, *args, **kwargs)¶
Create an
Operationinstance by specifying parameters (if any).Note that it is not linked to any
Nodeyet.
- classmethod on_new_circuit(circuit)¶
Callback on linking the operation class to a new circuit instance.
E.g. can store common circuit-level data in the circuit instance.
- before_create_node()¶
Validate node inputs before creating a new node with this operation.
- eval(value)¶
Evaluate the operation on given inputs (typically values, not nodes).
- class CONST(*values, **kvalues)¶
Bases:
OperationConstant node. Parameters:
value (circuit constant type): constant value to use
- eval()¶
Evaluate the operation on given inputs (typically values, not nodes).
- class GET(*values, **kvalues)¶
Bases:
OperationGetter node for multi-output nodes. Parameters:
index (int): index of the element to get
- before_create_node(node)¶
Validate node inputs before creating a new node with this operation.
- eval(x)¶
Evaluate the operation on given inputs (typically values, not nodes).
- __init__(base_ring=None, name=None, **kwargs)¶
- in_place_remove_unused_nodes()¶
WARNING: modifies the circuit (and nodes) in place
- trace(input, convert_input=True, convert_values=True, as_list=False)¶
Trace the circuit execution on a given input.
- Parameters
input (list[values]) – List of input values, one per input node.
convert_input (bool = True) – Convert input values using circuits
ConstManager?convert_values (bool = True) – Convert traced values using circuits
ConstManager?as_list (bool = False) – Output as list instead (with order defined by the circuit’s order)?
- Returns
trace
- Return type
dict[
Node, value]
- evaluate(input, convert_input=True, convert_output=True, with_mem=False)¶
- convert_input validates and converts input to the base_ring
element should be disabled e.g. for evaluating on Arrays (bit-sliced fashion), or for evaluating on symbolic objects (e.g. another circuit nodes).
- convert_output converts the output to a simple value, defined by
ConstManager maybe later we could specify different formats for conversion.
- concat_on_same_inputs(*circuits, name=None)¶
Concatenate two or more circuits by reusing the inputs
- concat_parallel(*circuits, name=None)¶
Concatenate two or more circuits fully in parallel
- print_stats(function=<built-in function print>, tab=' | ', exclude=[], by_address=False)¶
Shows basic information about the circuit.
Example
circuit.print_stats()
output:
circuit_name(ArithmeticCircuit): 32 inputs, 129 outputs, 8487 nodes