Skip to content

Commit

Permalink
Removed error case in append_circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
edyounis committed Oct 17, 2023
1 parent a5a224d commit b94ce8f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
9 changes: 4 additions & 5 deletions bqskit/ir/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,8 @@ def append_circuit(
(Default: False)
Returns:
int: The starting cycle index of the appended circuit.
int: The starting cycle index of the appended circuit. If the
appended circuit is empty, then this will be -1.
Raises:
ValueError: If `circuit` is not the same size as `location`.
Expand All @@ -1178,16 +1179,14 @@ def append_circuit(
op = Operation(CircuitGate(circuit, move), location, circuit.params)
return self.append(op)

cycle_index: int | None = None
cycle_index = -1

for op in circuit:
mapped_location = [location[q] for q in op.location]
ci = self.append(Operation(op.gate, mapped_location, op.params))
if cycle_index is None:
cycle_index = ci

if cycle_index is None:
raise RuntimeError('Cannot append empty circuit.')

return cycle_index

def extend(self, ops: Iterable[Operation]) -> None:
Expand Down
4 changes: 0 additions & 4 deletions tests/ir/circuit/test_op_gate_circ_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,13 @@ class TestAppendCircuit:

@given(circuits())
def test_reconstruct(self, circuit: Circuit) -> None:
if circuit.num_operations == 0:
return
new_circuit = Circuit(circuit.num_qudits, circuit.radixes)
new_circuit.append_circuit(circuit, list(range(circuit.num_qudits)))
check_no_idle_cycles(new_circuit)
assert new_circuit.get_unitary() == circuit.get_unitary()

@given(circuits())
def test_reconstruct_larger(self, circuit: Circuit) -> None:
if circuit.num_operations == 0:
return
new_circ = Circuit(circuit.num_qudits + 1, circuit.radixes + (2,))
new_circ.append_circuit(circuit, list(range(circuit.num_qudits)))
check_no_idle_cycles(new_circ)
Expand Down

0 comments on commit b94ce8f

Please sign in to comment.