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

Add support for controlled gates to mpl drawer #3779

Merged
merged 4 commits into from
Feb 5, 2020

Conversation

mtreinish
Copy link
Member

Summary

This commit adds support to the mpl drawer for drawing gates with an
arbitrary number of controls on them. Currently the drawer incorrectly
represents these gates as a large multiqubit custom gate. This fixes
that so it shows the original gate and then adds the controls to it.

Details and comments

Fixes #3763

This commit adds support to the mpl drawer for drawing gates with an
arbitrary number of controls on them. Currently the drawer incorrectly
represents these gates as a large multiqubit custom gate. This fixes
that so it shows the original gate and then adds the controls to it.

Fixes Qiskit#3763
@1ucian0
Copy link
Member

1ucian0 commented Feb 5, 2020

When

qr = QuantumRegister(3, 'q')
circuit = QuantumCircuit(qr)
circuit.append(HGate().control(2), [qr[0], qr[1], qr[2]])
circuit.draw('mpl')

I'm getting the following error:

qiskit-terra/qiskit/visualization/matplotlib.py in _draw_ops(self, verbose)
    844                         'ccx', 'cx', 'cz', 'cu1', 'ccz', 'cu3', 'crz',
    845                         'cswap']:
--> 846                     disp = op.op.base_gate_name
    847                     num_ctrl_qubits = op.op.num_ctrl_qubits
    848                     num_qargs = len(q_xy) - num_ctrl_qubits

AttributeError: 'ControlledGate' object has no attribute 'base_gate_name'

@ajavadia
Copy link
Member

ajavadia commented Feb 5, 2020

Yes base_gate_name got removed in #3773. This should now be base_gate.name

I think it's fine to do a box now and refine later if possible.

@mtreinish
Copy link
Member Author

Ok, I'll update this to adjust for that api change

In Qiskit#3773 the parameters for ControlledGate objects were changed in
an incompatible manner which removed the base_gate_name attribute
in favor of storing an instance of the inner gate class. This commit
updates the usage so that we can set the name of the gate correctly
in the visualization.
@1ucian0 1ucian0 added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Feb 5, 2020
@mergify mergify bot merged commit 153f527 into Qiskit:master Feb 5, 2020
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
* Add support for controlled gates to mpl drawer

This commit adds support to the mpl drawer for drawing gates with an
arbitrary number of controls on them. Currently the drawer incorrectly
represents these gates as a large multiqubit custom gate. This fixes
that so it shows the original gate and then adds the controls to it.

Fixes Qiskit#3763

* Update game name to reflect api changes

In Qiskit#3773 the parameters for ControlledGate objects were changed in
an incompatible manner which removed the base_gate_name attribute
in favor of storing an instance of the inner gate class. This commit
updates the usage so that we can set the name of the gate correctly
in the visualization.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MPL drawer does not support controlled gates
3 participants