From b94ce8f71c34cc2f54b27af71cef2e2eb3dcb632 Mon Sep 17 00:00:00 2001 From: Ed Younis Date: Tue, 17 Oct 2023 06:08:53 -0400 Subject: [PATCH] Removed error case in append_circuit --- bqskit/ir/circuit.py | 9 ++++----- tests/ir/circuit/test_op_gate_circ_methods.py | 4 ---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/bqskit/ir/circuit.py b/bqskit/ir/circuit.py index c924e2de4..d58b299a7 100644 --- a/bqskit/ir/circuit.py +++ b/bqskit/ir/circuit.py @@ -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`. @@ -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: diff --git a/tests/ir/circuit/test_op_gate_circ_methods.py b/tests/ir/circuit/test_op_gate_circ_methods.py index 13caca3a8..06f240874 100644 --- a/tests/ir/circuit/test_op_gate_circ_methods.py +++ b/tests/ir/circuit/test_op_gate_circ_methods.py @@ -339,8 +339,6 @@ 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) @@ -348,8 +346,6 @@ def test_reconstruct(self, circuit: Circuit) -> None: @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)