Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap library circuits #6634

Merged
merged 22 commits into from
Jul 7, 2021
Merged

Wrap library circuits #6634

merged 22 commits into from
Jul 7, 2021

Conversation

Cryoris
Copy link
Contributor

@Cryoris Cryoris commented Jun 24, 2021

Summary

Consistently wrap all library circuits into a gate, so that they appear as blocks when composing to another circuit.

Details and comments

Currently some library circuits are wrapped in a circuit block, some are not. This PR ensures that all are wrapped, so that

Examples

qc = QuantumCircuit(3)
qc.initialize(np.eye(8)[:, 3], range(3))
qc.compose(QFT(3).inverse(), inplace=True)
     ┌──────────────────────────────┐┌─────────┐
q_0: ┤0                             ├┤0        ├
     │                              ││         │
q_1: ┤1 initialize(0,0,0,1,0,0,0,0) ├┤1 QFT_dg ├
     │                              ││         │
q_2: ┤2                             ├┤2        ├
     └──────────────────────────────┘└─────────┘

Grover:

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

grover = GroverOperator(oracle)

qc = QuantumCircuit(3)
qc.h(range(3))
qc.compose(grover, inplace=True)
     ┌───┐┌────┐
q_0: ┤ H ├┤0   ├
     ├───┤│  Q │
q_1: ┤ H ├┤1   ├
     ├───┤└────┘
q_2: ┤ H ├──────
     └───┘

Amplitude estimation:

state_in = QuantumCircuit(1)
state_in.ry(0.2, 0)

oracle = QuantumCircuit(1)
oracle.z(0)

grover = GroverOperator(oracle, state_in)

ae = PhaseEstimation(3, grover)
ae.compose(state_in, [3], front=True, inplace=True)
                   ┌──────┐
eval_0: ───────────┤0     ├
                   │      │
eval_1: ───────────┤1     ├
                   │  QPE │
eval_2: ───────────┤2     ├
        ┌─────────┐│      │
   q_0: ┤ RY(0.2) ├┤3     ├
        └─────────┘└──────┘

and decomposed once:

            ┌───┐                             ┌──────┐
eval_0: ────┤ H ├────────■────────────────────┤2     ├
            ├───┤        │                    │      │
eval_1: ────┤ H ├────────┼───────■────────────┤1 QFT ├
            ├───┤        │       │            │      │
eval_2: ────┤ H ├────────┼───────┼───────■────┤0     ├
        ┌───┴───┴────┐┌──┴───┐┌──┴───┐┌──┴───┐└──────┘
   q_0: ┤ R(0.2,π/2) ├┤ Q**1 ├┤ Q**2 ├┤ Q**4 ├────────
        └────────────┘└──────┘└──────┘└──────┘

Todo

  • Wrap the blueprint circuits
  • Wrap newcomers to the circuit library (like arithmetic circuits)

@Cryoris Cryoris changed the title [WIP] Wrap library circuits Wrap library circuits Jun 29, 2021
@Cryoris Cryoris marked this pull request as ready for review June 29, 2021 13:17
@Cryoris Cryoris requested review from manoelmarques, woodsp-ibm and a team as code owners June 29, 2021 13:17
@ajavadia ajavadia added the Changelog: API Change Include in the "Changed" section of the changelog label Jul 7, 2021
@ajavadia ajavadia merged commit fcedd7e into Qiskit:main Jul 7, 2021
jwoehr added a commit to jwoehr/qiskit-tutorials that referenced this pull request Jan 9, 2022
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.
ElePT pushed a commit to ElePT/qiskit that referenced this pull request Jun 27, 2023
* start wrapping all plain QC library circuits

* fix more tests

* fix phase estimation test on QFT reverse bits

* black

* name QFT uppercase

* final test fixes

* GroverOp includes the global phase in inner circuit, don't add it to outer circuit
* Make sure ``unitary`` input to PhaseEstimation is a gate and not instruction

* wrap nlocal circuits

* blueprint circuits

* fix gradient tests

* wrap circuit library newcomers

* missing inner name in grover op

* wrap evolved op ansatz + QAOA

* fix qaoa tests

* rename inner->circuit

* add reno

* black
ElePT pushed a commit to ElePT/qiskit-algorithms-test that referenced this pull request Jul 17, 2023
* start wrapping all plain QC library circuits

* fix more tests

* fix phase estimation test on QFT reverse bits

* black

* name QFT uppercase

* final test fixes

* GroverOp includes the global phase in inner circuit, don't add it to outer circuit
* Make sure ``unitary`` input to PhaseEstimation is a gate and not instruction

* wrap nlocal circuits

* blueprint circuits

* fix gradient tests

* wrap circuit library newcomers

* missing inner name in grover op

* wrap evolved op ansatz + QAOA

* fix qaoa tests

* rename inner->circuit

* add reno

* black
robotastray pushed a commit to robotastray/qiskit-algorithms that referenced this pull request Aug 7, 2023
ElePT pushed a commit to ElePT/qiskit-algorithms that referenced this pull request Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: API Change Include in the "Changed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

compose should not unroll (by default) when using the circuit library
2 participants