question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MCMT generalized gate accepts a label kwarg that seems ignored

See original GitHub issue

Information

  • Qiskit Terra version: main @ c3792f9d
  • Python version: 3.6
  • Operating system: osx 10.15.7

What is the current behavior?

mcmt from library allows a label kwarg, but it doens’t go anywhere?

Steps to reproduce the problem

The generalized gate MCMT accepts a label kwarg, which it will set to be self.label, but as a subclass of QuantumCircuit, it does not look like this attribute will be read anywhere (or at least, I couldn’t find anywhere where it was used.)

>>> from qiskit.circuit.library import *
>>> MCMT(XGate(), 3, 1, label='foo').draw()
          
q_0: ──■──
       │  
q_1: ──■──
       │  
q_2: ──■──
     ┌─┴─┐
q_3: ┤ X ├
     └───┘
>>> MCMT(XGate(), 3, 1, label='foo').name
'mcmt'
>>> MCMT(XGate(), 3, 1, label='foo').to_instruction()
<qiskit.circuit.instruction.Instruction at 0x14b031898>
>>> MCMT(XGate(), 3, 1, label='foo').to_instruction().label
>>> MCMT(XGate(), 3, 1, label='foo').to_instruction().name
'mcmt'

What is the expected behavior?

Suggested solutions

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kevinhartmancommented, Oct 17, 2021

After some investigation, it looks like label is actually not ignored, though I imagine this is a bug.

When multiple target qubits are used, the name of the QuantumCircuit created for broadcast is set to the value of label. When control() is called on the resulting gate, that name is actually eventually used in some special-casing in add_control.py::control.

if gate.name == "x":
   controlled_circ.mct(q_control, q_target[bit_indices[qargs[0]]], q_ancillae)
elif gate.name == "rx":
  ...

I was able to get different circuits by specifying a special-cased label.

Default (label=“2-X”)

mcmt1 = MCMT(XGate(), num_ctrl_qubits=1, num_target_qubits=2)
print(mcmt1.qasm())
OPENQASM 2.0;
include "qelib1.inc";
gate c2-X q0,q1,q2 { cx q0,q1; cx q0,q2; }
qreg q[3];
c2-X q[0],q[1],q[2];

label=“x”

mcmt2 = MCMT(XGate(), num_ctrl_qubits=1, num_target_qubits=2, label="x")
print(mcmt2.qasm())
OPENQASM 2.0;
include "qelib1.inc";
qreg q[3];
cx q[0],q[1],q[2];

@kdk

1reaction
Cryoriscommented, Sep 2, 2021

I think a label doesn’t make much sense for the MCMT since it’s not drawn as a box but as multicontrolled gate. We could make label be the label of the controlled gate, or (probably the better, cleaner solution) just remove it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Source code for qiskit.circuit.library.generalized_gates.mcmt
if label is not None: warnings.warn( "The MCMT 'label' kwarg is deprecated as of qiskit-terra 0.19.0 and " "will be removed no earlier...
Read more >
How To Use *args and **kwargs in Python 3 - DigitalOcean
In this tutorial, we will cover the syntax of working with *args and **kwargs as parameters within functions to pass a variable number...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found