from cirbo.core import Circuit, Gate
from cirbo.minimization import cleanup
circ = Circuit.from_bench_file("data/circuit.bench")
circ = cleanup(circ)
---------------------------------------------------------------------------
CircuitValidationError Traceback (most recent call last)
Cell In[10], line 1
----> 1 circ = cleanup(circ)
2 # circ.into_graphviz_digraph()
File ~/Work/cirbo/cirbo/minimization/simplification/cleanup.py:28, in cleanup(circuit)
19 def cleanup(circuit: Circuit) -> Circuit:
20 """
21 Applies several simplification algorithms from this module consecutively in order to
22 simplify provided circuit.
(...)
26
27 """
---> 28 return Transformer.apply_transformers(
29 circuit,
30 [
31 RemoveRedundantGates(),
32 MergeUnaryOperators(),
33 MergeDuplicateGates(),
34 MergeEquivalentGates(),
35 ],
36 )
File ~/Work/cirbo/cirbo/core/circuit/transformer.py:100, in Transformer.apply_transformers(circuit, transformers)
97 _transformers = transformers
99 # apply transformers to the circuit.
--> 100 return functools.reduce(
101 lambda _circ, _transformer: _transformer._transform(_circ),
102 Transformer.linearize_reduce_transformers(_transformers),
103 circuit,
104 )
File ~/Work/cirbo/cirbo/core/circuit/transformer.py:101, in Transformer.apply_transformers.<locals>.<lambda>(_circ, _transformer)
97 _transformers = transformers
99 # apply transformers to the circuit.
100 return functools.reduce(
--> 101 lambda _circ, _transformer: _transformer._transform(_circ),
102 Transformer.linearize_reduce_transformers(_transformers),
103 circuit,
104 )
File ~/Work/cirbo/cirbo/minimization/simplification/merge_equivalent_gates.py:43, in MergeEquivalentGates._transform(self, circuit)
37 """
38 :param circuit: the original circuit to be simplified
39 :return: new simplified version of the circuit
40
41 """
42 equivalent_gate_groups = _find_equivalent_gates_groups(circuit)
---> 43 return _replace_equivalent_gates(circuit, equivalent_gate_groups)
File ~/Work/cirbo/cirbo/minimization/simplification/merge_equivalent_gates.py:119, in _replace_equivalent_gates(circuit, equivalent_groups)
116 return
118 # reconstruct circuit
--> 119 more_itertools.consume(
120 circuit.dfs(
121 circuit.outputs,
122 on_exit_hook=_process_gate,
123 unvisited_hook=_process_gate,
124 topsort_unvisited=True,
125 )
126 )
128 # reorder inputs according to original order
129 _new_circuit.set_inputs(circuit.inputs)
File ~/.cache/pypoetry/virtualenvs/cirbo-Ev1XhC9r-py3.10/lib/python3.10/site-packages/more_itertools/recipes.py:184, in consume(iterator, n)
181 # Use functions that consume iterators at C speed.
182 if n is None:
183 # feed the entire iterator into a zero-length deque
--> 184 deque(iterator, maxlen=0)
185 else:
186 # advance to the empty slice starting at position n
187 next(islice(iterator, n, n), None)
File ~/Work/cirbo/cirbo/core/circuit/circuit.py:2179, in Circuit._traverse_circuit(self, mode, start_gates, inverse, on_enter_hook, on_discover_hook, on_exit_hook, unvisited_hook, on_traversal_end_hook, topsort_unvisited)
2176 yield current_elem
2178 elif gate_states[current_elem.label] == TraverseState.ENTERED:
-> 2179 on_exit_hook(current_elem, gate_states)
2180 gate_states[current_elem.label] = TraverseState.VISITED
2181 queue.pop(pop_index)
File ~/Work/cirbo/cirbo/minimization/simplification/merge_equivalent_gates.py:111, in _replace_equivalent_gates.<locals>._process_gate(_gate, _)
107 nonlocal _new_circuit, _old_to_new_gate
109 # Add all gates, even equivalent ones, but link
110 # users of the latest to "keep" representative.
--> 111 _new_circuit.emplace_gate(
112 label=_gate.label,
113 gate_type=_gate.gate_type,
114 operands=tuple(map(_get_gate_new_name, _gate.operands)),
115 )
116 return
File ~/Work/cirbo/cirbo/core/circuit/circuit.py:456, in Circuit.emplace_gate(self, label, gate_type, operands, **kwargs)
445 """
446 Add gate in the circuit.
447
(...)
453
454 """
455 check_label_doesnt_exist(label, self)
--> 456 check_gates_exist(operands, self)
458 return self._emplace_gate(label, gate_type, operands, **kwargs)
File ~/Work/cirbo/cirbo/core/circuit/validation.py:32, in check_gates_exist(gates, circuit)
30 for gate_label in gates:
31 if not circuit.has_gate(gate_label):
---> 32 raise CircuitValidationError(
33 f'Gate {gate_label} are not initialized in the circuit',
34 )
CircuitValidationError: Gate z2 are not initialized in the circuit
To Reproduce
Expected behavior
Circuit is cleaned up
Desktop: