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

dissasembler does not handle multi-control gates correctly #6271

Closed
ColemanCollins opened this issue Apr 21, 2021 · 3 comments · Fixed by #6291
Closed

dissasembler does not handle multi-control gates correctly #6271

ColemanCollins opened this issue Apr 21, 2021 · 3 comments · Fixed by #6291
Labels
bug Something isn't working

Comments

@ColemanCollins
Copy link

ColemanCollins commented Apr 21, 2021

Information

  • Qiskit Terra version: 0.17
  • Python version: 3.9.2
  • Operating system: macOS 11.2.3 (Big Sur)

What is the current behavior?

When attempting to use assembler.disassemble on a Qobj with an mcx gate, the disassembler throws an error.

Steps to reproduce the problem

from qiskit import assembler, compiler
qc = QuantumCircuit(5,5)
qc.mcx([0,1,2,3], 4)
qobj = compiler.assemble(qc)
assembler.disassemble(qobj)

produces


~/anaconda3/envs/qiskit_env/lib/python3.9/site-packages/qiskit/assembler/disassemble.py in _experiments_to_circuits(qobj)
    128                     _inst = instr_method(*params, qubits, clbits)
    129                 else:
--> 130                     _inst = instr_method(*params, *qubits, *clbits)
    131             elif name == 'bfunc':
    132                 conditional['value'] = int(i.val, 16)

TypeError: mcx() takes from 3 to 5 positional arguments but 6 were given

a shorter version that doesn't break the argument number also hints at what's being passed being incorrect in some way:
(same input as above except qc.mcx([0,1,2],3))

~/anaconda3/envs/qiskit_env/lib/python3.9/site-packages/qiskit/circuit/quantumcircuit.py in mcx(self, control_qubits, target_qubit, ancilla_qubits, mode)
   2536         """
   2537         from .library.standard_gates.x import MCXGrayCode, MCXRecursive, MCXVChain
-> 2538         num_ctrl_qubits = len(control_qubits)
   2539 
   2540         available_implementations = {

TypeError: object of type 'Qubit' has no len()

What is the expected behavior?

correct disassembly into a circuit

Suggested solutions

I think what's happening here is that the signature for quantumcircuit.mcx expects a list of controls, followed by a target; mcx(control_qubits, target_qubit, ...) The qobj representation of an mcx gate is just a list of qubits, with (I think) the last being the target; L130 is unzipping the entire qubit list into the method, which does not match the signature.

granted, this might eventually be moot given #5897, but it looks like there needs to be another case in the disassembler for this gate and any like it that expect a list, or else a change in the gate def to accommodate this case.

@enavarro51
Copy link
Contributor

@ColemanCollins If you're not working on this, I think I have at least a rudimentary solution. It appears that 4 QuantumCircuit methods, mcx, mct, mcp, and mcu1 use the control_qubits list. (There may be others if we look through all the internally created gates, but I think fixing these will handle the immediate problem). It's easy to treat these as a special case in the disassembler.

If you'd like, I can submit a PR to fix this.

@ColemanCollins
Copy link
Author

@enavarro51 feel free! no feeling of ownership here and I wasn't planning on getting to it until the weekend

@enavarro51
Copy link
Contributor

Thanks. PR at #6291.

@mergify mergify bot closed this as completed in #6291 Apr 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants