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

Trying to control a custom gate calls unroll and raises an error #7114

Open
ianarawjo opened this issue Oct 11, 2021 · 1 comment
Open

Trying to control a custom gate calls unroll and raises an error #7114

ianarawjo opened this issue Oct 11, 2021 · 1 comment
Labels
bug Something isn't working synthesis

Comments

@ianarawjo
Copy link

ianarawjo commented Oct 11, 2021

Information

  • Qiskit Terra version: 0.18.3
  • Python version: 3.8.8
  • Operating system: Mac OS Big Sur 11.3.1

What is the current behavior?

Using .control(2) method on a custom Gate() produces an error.

Error output:

File "/opt/anaconda3/lib/python3.8/site-packages/qiskit/circuit/gate.py", line 119, in control
return add_control(self, num_ctrl_qubits, label, ctrl_state)
File "/opt/anaconda3/lib/python3.8/site-packages/qiskit/circuit/add_control.py", line 59, in add_control
cgate = control(operation, num_ctrl_qubits=num_ctrl_qubits, label=label, ctrl_state=ctrl_state)
File "/opt/anaconda3/lib/python3.8/site-packages/qiskit/circuit/add_control.py", line 113, in control
unrolled_gate = _unroll_gate(operation, basis_gates=basis)
File "/opt/anaconda3/lib/python3.8/site-packages/qiskit/circuit/add_control.py", line 268, in _unroll_gate
opqc = dag_to_circuit(unroller.run(dag))
File "/opt/anaconda3/lib/python3.8/site-packages/qiskit/transpiler/passes/basis/unroller.py", line 76, in run
raise QiskitError(
qiskit.exceptions.QiskitError: "Error decomposing node of instruction 'A': 'NoneType' object has no attribute 'global_phase'. Unable to define instruction 'A' in the given basis."

Steps to reproduce the problem

Code:

gateA = Gate(name='A', num_qubits=1, params=[])
ccA = gateA.control(2)

What is the expected behavior?

I expected that qiskit would allow the to-be-defined gate A to be added to the circuit, since I do not explicitly call "unroll." If I define the gate using 'ControlledGate' directly, where base_gate=gateA as init param, there's no error and I can add it to the circuit.

Suggested solutions

Waiting for developers to reply --possible this is a technical limitation of the way qiskit is implemented.

@ianarawjo ianarawjo added the bug Something isn't working label Oct 11, 2021
@ecpeterson
Copy link
Contributor

There's an effort currently underway (see, e.g., #7087) which includes an aim to decouple gates-as-circuit elements from gates-as-definitions. This bug belongs to that same class of issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working synthesis
Projects
None yet
Development

No branches or pull requests

2 participants