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

​Cannot unroll identity matrix of more than 2 qubits when coupling_map is set #4577

Closed
gousaiyang opened this issue Jun 15, 2020 · 2 comments · Fixed by #4596
Closed

​Cannot unroll identity matrix of more than 2 qubits when coupling_map is set #4577

gousaiyang opened this issue Jun 15, 2020 · 2 comments · Fixed by #4596
Assignees
Labels
bug Something isn't working
Milestone

Comments

@gousaiyang
Copy link

Information

  • Qiskit Terra version: 0.14.1
  • Python version: 3.8
  • Operating system: both Windows and Linux

What is the current behavior?

The transpile function fails to unroll an UnitaryGate containing an identity matrix of more than 2 qubits when the backend argument is set to be a remote quantum computer or the coupling_map argument is set.

Steps to reproduce the problem

>>> import numpy as np
>>> from qiskit import IBMQ, QuantumCircuit, transpile
>>> from qiskit.extensions import UnitaryGate
>>> provider = IBMQ.load_account()
>>> backend = provider.get_backend('ibmq_london')  # arbitrary backend with at least 3 qubits
>>> circuit = QuantumCircuit(3)
>>> gate = UnitaryGate(np.eye(2 ** 3))
>>> circuit.append(gate, range(3))
<qiskit.circuit.instructionset.InstructionSet object at 0x7ff8b93a60d0>
>>> transpile(circuit, backend=backend)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/qiskit/compiler/transpile.py", line 210, in transpile    circuits = parallel_map(_transpile_circuit, list(zip(circuits, transpile_args)))
  File "/usr/local/lib/python3.8/dist-packages/qiskit/tools/parallel.py", line 105, in parallel_map
    return [task(values[0], *task_args, **task_kwargs)]
  File "/usr/local/lib/python3.8/dist-packages/qiskit/compiler/transpile.py", line 306, in _transpile_circuit
    return pass_manager.run(circuit, callback=transpile_config['callback'],
  File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/passmanager.py", line 214, in run
    return self._run_single_circuit(circuits, output_name, callback)
  File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/passmanager.py", line 277, in _run_single_circuit
    result = running_passmanager.run(circuit, output_name=output_name, callback=callback)
  File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/runningpassmanager.py", line 115, in run
    dag = self._do_pass(pass_, dag, passset.options)
  File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/runningpassmanager.py", line 145, in _do_pass
    dag = self._run_this_pass(pass_, dag)
  File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/runningpassmanager.py", line 157, in _run_this_pass
    new_dag = pass_.run(dag)
  File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/passes/basis/unroll_3q_or_more.py", line 54, in run
    decomposition = self.run(decomposition)  # recursively unroll
  File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/passes/basis/unroll_3q_or_more.py", line 54, in run
    decomposition = self.run(decomposition)  # recursively unroll
  File "/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/passes/basis/unroll_3q_or_more.py", line 39, in run
    raise QiskitError("Cannot unroll all 3q or more gates. "
qiskit.exceptions.QiskitError: 'Cannot unroll all 3q or more gates. No rule to expand instruction circuit9_dg.'

Notes:

  • This bug only happens when the backend argument is set to be a remote quantum computer or the coupling_map argument is set to be a coupling map of a remote quantum computer. Calling transpile(circuit, basis_gates=['u1', 'u2', 'u3', 'cx', 'id']) works fine.
  • This bug only happens when the UnitaryGate contains an identity matrix of more than 2 qubits.

What is the expected behavior?

Successfully transpile the circuit.

@gousaiyang gousaiyang added the bug Something isn't working label Jun 15, 2020
@ajavadia ajavadia added this to the 0.15 milestone Jun 18, 2020
@kdk kdk self-assigned this Jun 18, 2020
Jonathan-Shoemaker pushed a commit to Jonathan-Shoemaker/qiskit-terra that referenced this issue Jun 19, 2020
…h more than 2 qubits. Required simple fix of throwing away empty operations when looping through 3+ qubit gates (used to just crash when it saw this).
@kdk kdk linked a pull request Jun 19, 2020 that will close this issue
@mergify mergify bot closed this as completed in #4596 Jun 19, 2020
mergify bot added a commit that referenced this issue Jun 19, 2020
* fixes #4577. No longer crashes upon unrolling of some gates with more than 2 qubits. Required simple fix of throwing away empty operations when looping through 3+ qubit gates (used to just crash when it saw this).

* fixed linting issues

* added release note

Co-authored-by: Jonathan-Shoemaker <Jonathan-Shoemaker@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this issue Aug 5, 2020
…iskit#4596)

* fixes Qiskit#4577. No longer crashes upon unrolling of some gates with more than 2 qubits. Required simple fix of throwing away empty operations when looping through 3+ qubit gates (used to just crash when it saw this).

* fixed linting issues

* added release note

Co-authored-by: Jonathan-Shoemaker <Jonathan-Shoemaker@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@EziOzoani
Copy link

Hi I think I'm getting a similar error

QiskitError: "Cannot unroll the circuit to the given basis, ['u0', 'u1', 'u2', 'u3', 'cx', 'x', 'y', 'z', 'h', 's', 't', 'snapshot']. Instruction id not found in equivalence library and no rule found to expand."

when I'm using the qiskit-jku-provider. It occurs when I try to execute the job with backend=jku_backend

@kdk
Copy link
Member

kdk commented Mar 12, 2021

Hi I think I'm getting a similar error

QiskitError: "Cannot unroll the circuit to the given basis, ['u0', 'u1', 'u2', 'u3', 'cx', 'x', 'y', 'z', 'h', 's', 't', 'snapshot']. Instruction id not found in equivalence library and no rule found to expand."

when I'm using the qiskit-jku-provider. It occurs when I try to execute the job with backend=jku_backend

Hi @EziOzoani , that error is raised because the circuit being transpiled contains an identity gate, but the backend does not report that it can implement an identity gate ('id' is not in the backend's basis_gates). The transpiler won't remove identity gates (id ) as they're generally left for the backend to decide how to implement (IBMQ backends, for example, have traditionally implemented id gates as an implicit delay, though this behavior will be removed in the future).

One option is to remove the id gates from your circuit before running it, or you can open an issue on the JKU provider suggesting the id gate be implemented. Feel free to reach out on the Qiskit Slack if you have further questions.

mergify bot pushed a commit that referenced this issue Oct 14, 2021
…4747)

* fixes #4577. No longer crashes upon unrolling of some gates with more than 2 qubits. Required simple fix of throwing away empty operations when looping through 3+ qubit gates (used to just crash when it saw this).

* fixed linting issues

* added release note

* Allow block collecting to collect groups up to any specified max size

* Updated many comments. Changed around some things to be simpler.

* Cleaned up Collect MultiQ Blocks Pass. Resolved issue where it would not handle classically conditioned gates properly.

* Fixed things discussed in review

* Remove stray release notes

* Unify processing condition checks

* Add release notes

Co-authored-by: Jonathan-Shoemaker <Jonathan-Shoemaker@ibm.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com>
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.

4 participants