Skip to content

Conversation

Cryoris
Copy link
Contributor

@Cryoris Cryoris commented Jun 29, 2021

Summary

Add the option to wrap circuits in QuantumCircuit.compose. This makes append for circuits obsolete so that for circuit compositions only compose is used.

Details and comments

If the circuit to compose is unitary and wrap=True, it will be added as Gate to maintain access to unitary operations such as control, otherwise as Instruction.

Here's a brief example:

from qiskit.circuit import QuantumCircuit

oracle = QuantumCircuit(2, name='Oracle')
oracle.cz(0, 1)

qc = QuantumCircuit(2)
qc.h(range(2))

qc.compose(oracle, wrap=True, inplace=True)
print(qc.draw())

yields

     ┌───┐┌─────────┐
q_0: ┤ H ├┤0        ├
     ├───┤│  Oracle │
q_1: ┤ H ├┤1        ├
     └───┘└─────────┘

@Cryoris Cryoris requested a review from a team as a code owner June 29, 2021 12:42
@1ucian0
Copy link
Member

1ucian0 commented Jul 1, 2021

Is this part of the plan to merge compose and append?

@Cryoris
Copy link
Contributor Author

Cryoris commented Jul 1, 2021

this makes append obsolete when using circuits, so concerning circuits this merges compose and append -- however for instructions/gates that's a different discussion 🙂

ajavadia
ajavadia previously approved these changes Jul 6, 2021
@ajavadia ajavadia added the Changelog: New Feature Include in the "Added" section of the changelog label Jul 6, 2021
Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
@mergify mergify bot merged commit 2c2fea0 into Qiskit:main Jul 7, 2021
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Mar 25, 2022
For the purpose of documentation many of the circuit library classes
were using the circuit_library_widget to provide a visualization of
the circuit, a QASM definition, and some basic high level statistics
about the circuit. However, since Qiskit#6634 and Qiskit#6659 all the circuit
library elements are wrapped in an outer Instruction object. This
makes the top level object appear as a logical block in the circuit.
This has the unindended side effect of causing the widget output to not
be super useful, primarily it would should a single logical block for
each element and the circuit statistics would be for the single element
as opposed to its implementation. This commit address this by adding a
single decompose() call around all the statistics and drawing calls
inside the widget code. Since we're consistently wrapping every circuit
library element the widget will always need to do this now, so instead
of calling it directly in the library docstring it's better to just do
this in the widget itself.
mergify bot pushed a commit that referenced this pull request Mar 25, 2022
For the purpose of documentation many of the circuit library classes
were using the circuit_library_widget to provide a visualization of
the circuit, a QASM definition, and some basic high level statistics
about the circuit. However, since #6634 and #6659 all the circuit
library elements are wrapped in an outer Instruction object. This
makes the top level object appear as a logical block in the circuit.
This has the unindended side effect of causing the widget output to not
be super useful, primarily it would should a single logical block for
each element and the circuit statistics would be for the single element
as opposed to its implementation. This commit address this by adding a
single decompose() call around all the statistics and drawing calls
inside the widget code. Since we're consistently wrapping every circuit
library element the widget will always need to do this now, so instead
of calling it directly in the library docstring it's better to just do
this in the widget itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants