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

An user should have an easy way to verify a circuit is compatible with a target backend #12916

Open
nonhermitian opened this issue Jul 23, 2024 · 15 comments
Assignees
Labels
type: enhancement It's working, but needs polishing

Comments

@nonhermitian
Copy link
Contributor

What is the expected feature or enhancement?

If I am given a circuit, I would like an easy way to verify if it is, or is not, compatible with a given backend.

Tket has such functionality: https://tket.quantinuum.com/api-docs/backends.html#pytket.backends.Backend.valid_circuit and it would be nice to include it here as well.

Acceptance criteria
There is an easy way to verify a circuit will run on a target backend.

@yaelbh
Copy link
Contributor

yaelbh commented Jul 23, 2024

Sounds like this belongs to Qiskit Core?

@jyu00
Copy link
Contributor

jyu00 commented Jul 30, 2024

@1ucian0 do you agree that this should be in Qiskit? Given Target lives in Qiskit, and this could apply to non-IBM target backend as well.

@1ucian0
Copy link
Member

1ucian0 commented Aug 3, 2024 via email

@yaelbh
Copy link
Contributor

yaelbh commented Aug 6, 2024

Is there already an issue in qiskit tracking this? I'd like to add some information.

First, FYI @nonhermitian the function https://github.com/Qiskit/qiskit-ibm-runtime/blob/3a9b08ed422e0de52981275537340c0a2af7a75b/qiskit_ibm_runtime/utils/utils.py#L78 I believe this is what you're looking for.

Note that currently the function is suspected to contain a bug, tracked in Qiskit/qiskit-ibm-runtime#1843.

Second, when the function is written in qiskit, I recommend not to write from scratch but to copy from qiskit-ibm-runtime. Although it looks easy, as you see it's not entirely trivial (we've spotted at least two bugs since its first version), so it will be a pity to repeat the same mistakes again in qiskit.

@nonhermitian
Copy link
Contributor Author

It is a bit confusing calling it an isa check. I don't think the underlying topology is part of the isa.

@yaelbh
Copy link
Contributor

yaelbh commented Aug 6, 2024

The documentation related to ISA from the beginning has always included connectivity, see for example https://www.ibm.com/quantum/blog/isa-circuits and https://docs.quantum.ibm.com/guides/get-started-with-primitives.

@nonhermitian
Copy link
Contributor Author

Huh, did not know that. The implication is that every Eagle has a different ISA.

@1ucian0
Copy link
Member

1ucian0 commented Aug 7, 2024

Transfering to Qiskit/qiskit

@1ucian0 1ucian0 transferred this issue from Qiskit/qiskit-ibm-runtime Aug 7, 2024
@raynelfss
Copy link
Contributor

I'll take a look into this. I'm assuming we could evaluate the instructions present in the circuit, as well as the parameters bound to them, with the Target's instruction_supported method.

@raynelfss raynelfss self-assigned this Aug 8, 2024
@yaelbh
Copy link
Contributor

yaelbh commented Aug 8, 2024

This is what's done in qiskit-ibm-runtime, you can copy from there (up to a potential bug).

@jakelishman
Copy link
Member

Fwiw, we have the GatesInBasis transpiler pass, which is most of the logic of the ask here already:

from qiskit.transpiler.passes import GatesInBasis

def is_supported(circuit, target):
    pass_ = GatesInBasis(target=target)
    pass_(circuit)
    return pass_.property_set["all_gates_in_basis"]

(or something like that). Maybe the next step of discussion is whether this can be done purely by documentation, or if there should be a helper function, and if so, what its API should be.

@yaelbh
Copy link
Contributor

yaelbh commented Aug 8, 2024

Thanks @jakelishman, does the pass take into account also connectivity?

@jakelishman
Copy link
Member

jakelishman commented Aug 8, 2024

Yeah, if the input is a Target we check things precisely. It also handles control-flow ops, etc.

@yaelbh
Copy link
Contributor

yaelbh commented Aug 19, 2024

@jake-lishman I'm not familiar with the DAG representation that the pass is using. In qiskit-ibm-runtime we skip instructions with calibrations: https://github.com/Qiskit/qiskit-ibm-runtime/blob/157233c731433067f6e2860b7795d8fd14efcf0d/qiskit_ibm_runtime/utils/utils.py#L63.

Will the pass do something equivalent?

@jakelishman
Copy link
Member

Looking at it now, that pass doesn't check calibrations. I'm not entirely familiar with the calibration-level workflows (so maybe there's a reason), but that does feel slightly awkward to me that it doesn't.

@1ucian0 1ucian0 added type: enhancement It's working, but needs polishing and removed enhancement labels Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement It's working, but needs polishing
Projects
None yet
Development

No branches or pull requests

6 participants