-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
QuantumCircuit.compose
on unusual types and registers (#9206)
* Fix `QuantumCircuit.compose` on unusual types and registers `QuantumCircuit.compose` previously had its own handling for converting bit specifiers into bit instances, meaning its functionality was often surprisingly less permissive than `append`, or just incorrect. This swaps the method to use the standard conversion utilities. The logic for handling mapping conditional registers was previously the old logic in `DAGCircuit`, which was called without respect to re-ordering of the clbits during the composition. The existing test case surrounding this that is modified by this commit made an incorrect assertion; in general, the condition was not the same after the composition. In this particular test case it was ok because both bits were being tested for the same value, but had the condition value been 0b01 or 0b10 it would have been incorrect. This commit updates the register-mapping logic to respect the reordering of clbits, and to create a new aliasing register to ensure the condition is represented exactly, if this is required. This fixes a category of bug where too-small registers could incorrectly be mapped to larger registers. This was not a valid transformation, because it created assertions about bits that were previously not involved in the condition's comparison. * Remove now-outdated DAG compose test This test was actually attempting to catch invalid state of `QuantumCircuit.compose`, but this series of commits changes the underlying function so that this test no longer needs to raise; there is valid alternative behaviour. * Fix lint * Add comment explaining list copy * Update test/python/circuit/test_compose.py Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
7ed5de3
commit 2629079
Showing
4 changed files
with
137 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
fixes: | ||
- | | ||
The method :meth:`.QuantumCircuit.compose` now accepts the same set of qubit and clbit | ||
specifiers as other :class:`.QuantumCircuit` methods, such as :meth:`~.QuantumCircuit.append`. | ||
This means, for example, that Numpy integers will work. Fixed `#8691 | ||
<https://github.com/Qiskit/qiskit-terra/issues/8691>`__. | ||
- | | ||
Fixed :meth:`.QuantumCircuit.compose` incorrectly mapping registers in conditions on the given | ||
circuit to complete registers on the base. Previously, the mapping was very imprecise; the bits | ||
used within each condition were not subject to the mapping, and instead an inaccurate attempt was | ||
made to find a corresponding register. This could also result in a condition on a smaller register | ||
being expanded to be on a larger register, which is not a valid transformation. Now, a | ||
condition on a single bit or a register will be composed to be on precisely the bits as defined | ||
by the ``clbits`` argument. A new aliasing register will be added to the base circuit to | ||
facilitate this, if necessary. Fixed `#6583 <https://github.com/Qiskit/qiskit-terra/issues/8691>__`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters