Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
4.85k stars 2.29k forks source link

specifying nonexistent synthesis plugin does not raise error #11355

Closed kevinsung closed 7 months ago

kevinsung commented 7 months ago

Environment

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.

rupeshknn commented 7 months ago

Can you assign me to this?

rupeshknn commented 7 months ago

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 commented 7 months ago

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.