Announcing Q# Bridge - a library bringing the Q# simulator and tools to C#, Swfit and Kotlin

Β· 624 words Β· 3 minutes to read

Over the past year, Q# and the QDK, have undergone a massive transformation, with the entire toolchain moving to Rust - which resulted in a significant performance improvement, better portability of the toolchain and the ability to run Q# on a wide range of platforms. This was especially striking compared to the 0.x versions of the QDK, which was coupled to the .NET SDK.

Today I would like to announce a new Q# ecosystem project called Q# Bridge, built under the Q# Community organization, which acts as a wrapper around the Q# simulator and tools, allowing you to easily use them from C#, Swift and Kotlin. The library is designed to be a lightweight wrapper around the Q# tooling, providing a simple API to interact with the Q# simulator and tools (such as resource estimation, QIR generation or circuit descriptions), without the need to write any Rust code or deal with marshaling or FFI directly.

Overview πŸ”—

When building educational or research tools around quantum computing, it is often desirable to have a way to interact with the Q# simulator and tools from a high-level language such as C#, Swift or Kotlin. Given that Q# toolchain is written in Rust, it is already compatible with all of the platforms those languages could run on - however, the interoperability, FFI, memory marshaling and other low-level details can be a significant barrier to entry for many developers.

This is exactly the value proposition of Q# Bridge - the seamless integration of Q# tools into all kinds of applications (both desktop and mobile) written in those languages (Python is also supported, though that has native QDK interop too), by exposing language bindings.

For example, you could author and iOS app, and use Q# Bridge to simply call the Swift APIs run a quantum algorithm on the Q# simulator, estimate the resources required to run a quantum algorithm on a real quantum computer or generate a circuit description for that algorithm. Or you could write a desktop app in C# that uses Q# Bridge and it’s C# facade to generate QIR for a Q# program and then analyze it.

The library does not re-export the Q#/QDK Rust APIs directly, but instead provides a subset of simplified APIs that are easier to use from high-level languages. The library is designed to be lightweight, with minimal overhead, and is easy to include in your project.

A basic example for simulating a Q# program using Q# Bridge is shown below.


var qsharpSource = "..."; // load from somewhere e.g. file or user input
var results = QsharpBridgeMethods.RunQsShots(qsharpSource, 10);
// iterate through results


let qsharpSource = "..."; // load from somewhere e.g. file or user input
let results = try runQsShots(source: qsharpSource, shots: 10)
// iterate through results


val qsharpSource = "..."; // load from somewhere e.g. file or user input
val results = runQsShots(qsharpSource, 10.toUInt())
// iterate through results

You can explore the repository on Github, where you can find samples of including the library in C#, Swift and Kotlin apps.

What’s next? πŸ”—

The APIs will continue to evolve as the library matures, and will be expanded to include more functionality from the Q# toolchain. The library is also open to contributions, so if you have an idea for a feature or a use case that is not covered by the library, feel free to open an issue or a pull request.

At the moment, for Swift and Kotlin only language bindings are generated. I will be working of packaging the library for Swift and Kotlin - as both xcframework and AAR, to make it easier to include Q# Bridge mobile projects. For C#, there is additionally a NuGet package being generated, which will be published to NuGet soon.


Hi! I'm Filip W., a cloud architect from ZΓΌrich πŸ‡¨πŸ‡­. I like Toronto Maple Leafs πŸ‡¨πŸ‡¦, Rancid and quantum computing. Oh, and I love the Lowlands 🏴󠁧󠁒󠁳󠁣󠁴󠁿.

You can find me on Github and on Mastodon.

My Introduction to Quantum Computing with Q# and QDK book
Microsoft MVP