Skip to content

Commit 2595d8d

Browse files
Remove redundant name check when adding QuantumCircuit registers. (#16678)
* remove redundant name check for add_register on the python side * add performance release note * modify performance release note * remove create registers test file * modify release notes with performance details * improve release notes language * touch on redundant error handling in release note * remove test program * fix release note typo * Update releasenotes/notes/create-register-performance-fe392209793d151f.yaml Co-authored-by: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com> * Apply suggestion from @raynelfss Co-authored-by: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com> --------- Co-authored-by: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com>
1 parent d94420a commit 2595d8d

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

qiskit/circuit/quantumcircuit.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3636,11 +3636,6 @@ def add_register(self, *regs: Register | int | Sequence[Bit]) -> None:
36363636
)
36373637

36383638
for register in regs:
3639-
if isinstance(register, Register) and any(
3640-
register.name == reg.name for reg in self.qregs + self.cregs
3641-
):
3642-
raise CircuitError(f'register name "{register.name}" already exists')
3643-
36443639
if isinstance(register, AncillaRegister):
36453640
for bit in register:
36463641
if bit not in self._qubit_indices:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
performance:
2+
- |
3+
Improves runtime performance of the :py:meth:`~.QuantumCircuit.add_register()` method on
4+
:py:class:`~.QuantumCircuit`. Consequently, this change improves performance when
5+
creating :py:class:`~.QuantumCircuit` as well. Generally, the time complexity of
6+
checking register name presence was reduced to :math:`O(1)` from :math:`O(n)`. This was
7+
achieved by removing redundant error checking.

0 commit comments

Comments
 (0)