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

specifying nonexistent synthesis plugin does not raise error #11355

Closed
kevinsung opened this issue Nov 30, 2023 · 3 comments · Fixed by #11367
Closed

specifying nonexistent synthesis plugin does not raise error #11355

kevinsung opened this issue Nov 30, 2023 · 3 comments · Fixed by #11367
Labels
bug Something isn't working

Comments

@kevinsung
Copy link
Contributor

kevinsung commented Nov 30, 2023

Environment

  • Qiskit Terra version: 0.45.1
  • Python version: 3.10.12
  • Operating system: Arch Linux

What is happening?

generate_preset_pass_manager does not raise an error for a nonexistent synthesis plugin, even though it does for a nonexistent stage plugin.

How can we reproduce the issue?

from qiskit.providers.fake_provider import FakeBelem
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

backend = FakeBelem()
pass_manager = generate_preset_pass_manager(
    optimization_level=3, backend=backend, unitary_synthesis_method="a"
)

What should happen?

This does not raise an error. Instead, an error is raised when the pass manager is run. This is inconsistent with the transpiler stage plugins. For example, this raises an error:

from qiskit.providers.fake_provider import FakeBelem
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

backend = FakeBelem()
pass_manager = generate_preset_pass_manager(
    optimization_level=3, backend=backend, routing_method="a"
)
TranspilerError: 'Invalid plugin name a for stage routing'

Any suggestions?

The error should be raised when the pass manager is created, not when it is run.

@kevinsung kevinsung added the bug Something isn't working label Nov 30, 2023
@rupeshknn
Copy link
Contributor

rupeshknn commented Dec 2, 2023

Can you assign me to this?

@rupeshknn
Copy link
Contributor

rupeshknn commented Dec 3, 2023

I was playing around with generate_preset_pass_manager and couldn't find a way to do unitary synthesis this way. For example:

from qiskit.providers.fake_provider import FakeBelem
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

backend = FakeBelem()
pass_manager = generate_preset_pass_manager(
    optimization_level=3, backend=backend, unitary_synthesis_method="aqc"
)
pass_manager.run(matrix)

Throws errors complaining that basically say matrix is not a QuantumCircuit. It queries methods like name, global_phase, and calibrations. How to use a pass manager or essentially qiskit.transpile to do unitary synthesis?

@mtreinish
Copy link
Member

The input to .run() is a QuantumCircuit object, so you'll need to put the matrix on a circuit for the transpiler to work with it. The easiest way is to do something like:

qc = QuantumCircuit(num_qubits)
qc.unitary(matrix, range(num_qubits))

and then pass qc to .run().

The other option is to manually call the aqc synthesis directly. There is a code sample on how to do this here: https://docs.quantum.ibm.com/api/qiskit/synthesis_aqc but it's much more manual.

To solve the original issue we just need to add a check to UnitarySynthesis's __init__ method that the user specified plugin is valid. Right now it only gets checked during UnitarySynthesis.run which is why it doesn't error until the passmanager is run.

rupeshknn added a commit to rupeshknn/qiskit that referenced this issue Dec 4, 2023
github-merge-queue bot pushed a commit that referenced this issue Dec 5, 2023
* fix issue #11355

* update docstring

* added test

* rename non-method

* Update releasenotes/notes/move-synthesis-plugin-error-61e3683bf5a0c225.yaml

* Reword messages

---------

Co-authored-by: Kevin J. Sung <[email protected]>
Co-authored-by: Jake Lishman <[email protected]>
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.

3 participants