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

Add C FFI for Circuit Construction and transpilation #13276

Open
mtreinish opened this issue Oct 3, 2024 · 4 comments
Open

Add C FFI for Circuit Construction and transpilation #13276

mtreinish opened this issue Oct 3, 2024 · 4 comments
Labels
Rust This PR or issue is related to Rust code in the repository
Milestone

Comments

@mtreinish
Copy link
Member

What should we add?

After we have the full rust-native core data model in #13264 we can then expose a compiled language interface directly to that data model. Having a compiled language interface will let users from other programming languages besides Python leverage Qiskit for quantum computation. But also for Python users having this interface would let Python compiled extensions interface with Qiskit at a lower level directly from the extension. This can be exceedingly powerful for accelerating applications of Qiskit in python, the best example is numpy which exposes a C API which is how Qiskit interfaces with numpy arrays from Rust and has been key for our performance as we've been doing more in Rust.

A C FFI is a natural choice for this as most languages can interface with C, including Python and Rust, and defining a C API via rust is very simple, see: https://doc.rust-lang.org/nomicon/ffi.html#calling-rust-code-from-c.

To start this interface should be very low level and only express a basic interface for building a QuantumCircuit with standard gates (or other operations defined solely by Qiskit in rust) and then transpiling that circuit (and maybe individual transpiler pass functions). Also, I think to start we should consider this API experimental and not commit to it being a fully stable interface as Qiskit has never had an API like this before, but we should also strive to keep the interface public and stable as defined by the stability policy. Basically say it'll be stable but not guarantee it at least for the first few releases while we figure out the best patterns here.

@mtreinish mtreinish added the Rust This PR or issue is related to Rust code in the repository label Oct 3, 2024
@mtreinish mtreinish added this to the 2.0.0 milestone Oct 3, 2024
@mtreinish
Copy link
Member Author

The other tool which might be useful in this effort is cbindgen, the docs for this are here: https://github.com/mozilla/cbindgen/blob/master/docs.md

@DisantHoridnt
Copy link

I am looking into this issue

@Cryoris
Copy link
Contributor

Cryoris commented Dec 10, 2024

Thank you for your interest @DisantHoridnt. Due to the scope of this issue, we’re currently handling it in the maintainer team. However, once we've advanced on this, contributions on concrete, smaller-scoped tasks would be welcome!

@DisantHoridnt
Copy link

sounds good, I currently am employed as a rust engineer who is responsible for translating c++ code. I might be able to help

@1ucian0 1ucian0 modified the milestones: 2.0.0, 2.1.0 Jan 28, 2025
mtreinish added a commit to mtreinish/qiskit-core that referenced this issue Mar 12, 2025
Building off the infrastructure for the sparse observable added in
PR Qiskit#13445 this commit adds a C FFI for building Quantum Circuits. Right
now there is a function to create an empty circuit with n qubits and m
clbits and then a function to add standard gates to a circuit and then
also get the op counts out of a circuit. This is a start of the
functionality for a C API around interacting with circuits, later PRs
will expand this so we can have a more fully featured C API in the
future.

Part of Qiskit#13276
mtreinish added a commit to mtreinish/qiskit-core that referenced this issue Mar 12, 2025
Building off the infrastructure for the sparse observable added in
PR Qiskit#13445 this commit adds a C FFI for building Quantum Circuits. Right
now there is a function to create an empty circuit with n qubits and m
clbits and then a function to add standard gates to a circuit and then
also get the op counts out of a circuit. This is a start of the
functionality for a C API around interacting with circuits, later PRs
will expand this so we can have a more fully featured C API in the
future.

Part of Qiskit#13276
mtreinish added a commit to mtreinish/qiskit-core that referenced this issue Mar 12, 2025
Building off the infrastructure for the sparse observable added in
PR Qiskit#13445 this commit adds a C FFI for building Quantum Circuits. Right
now there is a function to create an empty circuit with n qubits and m
clbits and then a function to add standard gates to a circuit and then
also get the op counts out of a circuit. This is a start of the
functionality for a C API around interacting with circuits, later PRs
will expand this so we can have a more fully featured C API in the
future.

Part of Qiskit#13276
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

No branches or pull requests

4 participants