{"id":25528855,"url":"https://github.com/thenewjavaman/brac-kt","last_synced_at":"2025-04-11T07:55:13.678Z","repository":{"id":57166051,"uuid":"432280436","full_name":"TheNewJavaman/brac-kt","owner":"TheNewJavaman","description":"A Kotlin/Multiplatform interface for quantum computing","archived":false,"fork":false,"pushed_at":"2022-11-12T11:25:48.000Z","size":10687,"stargazers_count":2,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-24T09:05:34.978Z","etag":null,"topics":["c","cpp","csharp","ibm-q","ibm-q-experience","java","javascript","jvm","kotlin","kotlin-js","kotlin-jvm","kotlin-multiplatform","kotlin-native","quantum","quantum-computing","typescript"],"latest_commit_sha":null,"homepage":"https://javaman.net/brac-kt","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheNewJavaman.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-26T19:21:50.000Z","updated_at":"2023-12-06T11:03:22.000Z","dependencies_parsed_at":"2023-01-22T20:00:11.551Z","dependency_job_id":null,"html_url":"https://github.com/TheNewJavaman/brac-kt","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNewJavaman%2Fbrac-kt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNewJavaman%2Fbrac-kt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNewJavaman%2Fbrac-kt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNewJavaman%2Fbrac-kt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheNewJavaman","download_url":"https://codeload.github.com/TheNewJavaman/brac-kt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248360032,"owners_count":21090635,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","cpp","csharp","ibm-q","ibm-q-experience","java","javascript","jvm","kotlin","kotlin-js","kotlin-jvm","kotlin-multiplatform","kotlin-native","quantum","quantum-computing","typescript"],"created_at":"2025-02-19T23:23:42.340Z","updated_at":"2025-04-11T07:55:13.639Z","avatar_url":"https://github.com/TheNewJavaman.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![](https://img.shields.io/github/workflow/status/TheNewJavaman/brac-kt/Code%20Linting%20(Detekt)/main?label=Code%20Linting\u0026cacheSeconds=1)](https://github.com/TheNewJavaman/brac-kt/actions/workflows/linting.yml)\n[![](https://img.shields.io/github/workflow/status/TheNewJavaman/brac-kt/Tests%20(Kotlin%20Multiplatform)/main?label=Tests\u0026cacheSeconds=1)](https://github.com/TheNewJavaman/brac-kt/actions/workflows/tests.yml)\n[![](https://img.shields.io/github/workflow/status/TheNewJavaman/brac-kt/Publish%20Docs%20(Dokka)/main?label=Docs\u0026cacheSeconds=1)](https://javaman.net/brac-kt)\n[![](https://img.shields.io/jitpack/v/github/TheNewJavaman/brac-kt?color=informational\u0026label=JitPack\u0026cacheSeconds=1)](https://jitpack.io/#net.javaman.brac-kt/brac-kt)\n[![](https://img.shields.io/badge/JitPack-main--SNAPSHOT-informational)](https://jitpack.io/#net.javaman.brac-kt/brac-kt)\n[![](https://img.shields.io/npm/v/@thenewjavaman/brac-kt-api?color=informational\u0026cacheSeconds=1)](https://www.npmjs.com/~thenewjavaman)\n[![](https://img.shields.io/tokei/lines/github/TheNewJavaman/brac-kt?color=important\u0026label=Total%20Lines)](https://github.com/TheNewJavaman/brac-kt)\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003cimg src=\"resources/full-outline-downsized.png\" alt=\"branding\" width=1750/\u003e\u003c/td\u003e\n\u003ctd\u003e\n\u003ch1\u003ebrac-kt\u003c/h1\u003e\n\nA Kotlin/Multiplatform interface for quantum computing\n\u003c/td\u003e  \n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd colspan=2 align=\"center\"\u003e\n\u003ci\u003eNamed after bra-ket quantum notation (with \"kt\" for Kotlin), pronounced \"bracket\"\u003c/i\u003e\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n## Support\n\nWrite quantum circuits in any major language:\n\n\u003ctable\u003e\n\u003ctr\u003e\u003c/tr\u003e\n\u003ctr\u003e\n\u003cth\u003eJava Virtual Machine\u003c/th\u003e\n\u003cth\u003eJavaScript Runtimes (Browser, Node.js)\u003c/th\u003e\n\u003cth\u003eNative Platforms (Windows, Linux)\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n- Java\n- Kotlin\n- Groovy\n- Scala\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n- JavaScript\n- TypeScript\n- Kotlin\n- CoffeeScript\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n- C\n- C++\n- C#\n- Kotlin\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n## Installation\n\nThe brac-kt API will be included with any providers you install.\n\n### Gradle (JVM)\n\nAdd to `build.gradle.kts`:\n\n```kotlin\nrepositories {\n    mavenCentral()\n    maven {\n        url = uri(\"https://jitpack.io\")\n    }\n}\n\ndependencies {\n    implementation(\"net.javaman.brac-kt:brac-kt-ibmq-provider\")\n}\n```\n\n### npm (JS)\n\nInstall via `npm`:\n\n```shell\nnpm i @thenewjavaman/brac-kt-ibmq-provider\n```\n\n### Shared Library and Headers (Native)\n\nDownload from [the releases page](https://github.com/TheNewJavaman/brac-kt/releases). \n\nYou'll need libcurl. It's on most Linux installations by default, or you can get it on MinGW (Windows) through `pacman`.\n\n## Examples\n\n### Kotlin (JVM)\n\n```kotlin\nobject Application {\n    init {\n        BracKtApi.addInjections()\n        IbmqProvider.addInjections()\n    }\n\n    private val propertyManager: PropertyManager by injection()\n    private val ibmqProvider: IbmqProvider by injection()\n\n    @JvmStatic\n    fun main(args: Array\u003cString\u003e) {\n        val n = 3\n        val qc = QuantumCircuit(name = \"Example Superposition\", numQubits = 3) {\n            repeat(n) { h(qubit = it) }\n            repeat(n) { measure(qubit = it, bit = it) }\n        }\n\n        val apiToken: String = propertyManager[\"IBMQ_API_TOKEN\"]\n        ibmqProvider.logInSync(apiToken)\n        ibmqProvider.selectNetworkSync()\n        ibmqProvider.selectDeviceSync()\n        ibmqProvider.runExperimentAndWaitSync(qc)\n    }\n}\n```\n\n### Java (JVM)\n\n```java\npublic class Application {\n    static {\n        BracKtApi.addInjections();\n        IbmqProvider.addInjections();\n    }\n\n    private static final IbmqProvider ibmqProvider = new IbmqProvider();\n\n    public static void main(String[] args) {\n        int n = 3;\n        QuantumCircuit qc = new QuantumCircuit(\"Example Superposition\", n);\n        for (int i = 0; i \u003c n; i++) qc.h(i);\n        for (int i = 0; i \u003c n; i++) qc.measure(i, i);\n\n        String apiToken = System.getenv(\"IBMQ_API_TOKEN\");\n        ibmqProvider.logInSync(apiToken);\n        ibmqProvider.selectNetworkSync();\n        ibmqProvider.selectDeviceSync();\n        ibmqProvider.runExperimentAndWaitSync(qc);\n    }\n}\n```\n\n### TypeScript (JS)\n\n```typescript\nconst app = async () =\u003e {\n    bracKt.api.addInjections();\n    bracKt.providers.ibmq.addInjections();\n\n    const n = 3;\n    const qc = new QuantumCircuit(\"Example Superposition\", 3);\n    for (let i = 0; i \u003c n; i++) qc.h(i);\n    for (let i = 0; i \u003c n; i++) qc.measure(i, i);\n\n    const ibmqProvider = new IbmqProvider();\n    await ibmqProvider.logInAsync(process.env.IBMQ_API_TOKEN);\n    await ibmqProvider.selectNetworkAsync();\n    await ibmqProvider.selectDeviceAsync();\n    await ibmqProvider.runExperimentAndWaitAsync(qc);\n};\n```\n\n### C++ (Native)\n\n```cpp\nint main(int argc, char **argv) {\n    BracKt *bracKt = libbrac_kt_ibmq_provider_symbols();\n    bracKt-\u003eapi.addInjections();\n    bracKt-\u003eibmq_provider.addInjections();\n\n    int n = 3;\n    QuantumCircuit qc = bracKt-\u003eapi.quantum.QuantumCircuit.QuantumCircuit_(\"Example Superposition\", n, n);\n    for (int i = 0; i \u003c n; i++) bracKt-\u003eapi.quantum.QuantumCircuit.h(qc, i);\n    for (int i = 0; i \u003c n; i++) bracKt-\u003eapi.quantum.QuantumCircuit.measure(qc, i, i);\n\n    IbmqProvider ibmqProvider = bracKt-\u003eibmq_provider.IbmqProvider.IbmqProvider();\n    bracKt-\u003eibmq_provider.IbmqProvider.logInSync(ibmqProvider, getenv(\"IBMQ_API_TOKEN\"));\n    bracKt-\u003eibmq_provider.IbmqProvider.selectNetworkSync(ibmqProvider);\n    bracKt-\u003eibmq_provider.IbmqProvider.selectDeviceSync_(ibmqProvider, true, n);\n    bracKt-\u003eibmq_provider.IbmqProvider.runExperimentAndWaitSync(ibmqProvider, qc);\n}\n```\n\n### Output\n\nEvery example outputs:\n\n```\n...\n[...] [INFO ] Qubit outcomes:\n[...] [INFO ]     0x0: 0.12890625 (132/1024)\n[...] [INFO ]     0x1: 0.12792969 (131/1024)\n[...] [INFO ]     0x2: 0.13769531 (141/1024)\n[...] [INFO ]     0x3: 0.12695312 (130/1024)\n[...] [INFO ]     0x4: 0.1171875 (120/1024)\n[...] [INFO ]     0x5: 0.12109375 (124/1024)\n[...] [INFO ]     0x6: 0.109375 (112/1024)\n[...] [INFO ]     0x7: 0.13085938 (134/1024)\n```\n\n## Multiplatform Support\n\nIntegrating with other languages is seamless because brac-kt compiles into Java bytecode and JavaScript with TypeScript\ndefinitions. Additionally, each platform has its own unique features; for example, Java and C/C++ have additional\nsynchronous API methods, whereas JavaScript has async/await versions. Kotlin on all platforms gets a few unique\nfeatures: a cross-platform property manager, dependency injection, and all-around cleaner syntax.\n\n## Goals\n\nWhat am I trying to accomplish?\n\n### Summary\n\n1. Write quantum circuits once, run on any hardware\n2. Write quantum circuits in any major language using the same library (see Support above)\n3. Simplify the quantum development process\n\n### Details\n\n1. Write quantum circuits once, run on any hardware\n    - Each hardware provider provides their own tools, which can't cross-compile\n    - Make it easy to test on different providers\n    - Make it easy to switch providers when new features become available\n2. Write quantum circuits in any major language using the same library\n    - Replace standard Python libraries with a pure Kotlin/Multiplatform implementation\n        - Python has many limitations:\n            - Restricted to only the Python runtime\n            - Not type-safe, null-safe; prone to runtime errors\n            - Slow for non-C implementations; limits choices for big projects\n            - Not well-adopted outside of data science\n        - Kotlin fixes these issues:\n            - Can run on the JVM, JS (browser or node.js), and native runtimes\n            - Type-safe, null-safe; compile-time checks safeguard the development process\n            - Very performant, especially for server applications on the JVM\n            - Can run on any major runtime, so it can interop with most popular libraries\n                - JVM: Desktop applications, servers\n                - JS: Desktop apps, websites, sometimes servers (although they're less performant)\n                - Native: Desktop applications, interop with legacy/low-level software, workstations tasks (scientific\n                  research)\n    - Easy to develop fullstack apps using one library in both frontend and backend\n    - Provides more options for beginners, easier for people with non-data science backgrounds\n3. Simplify quantum development process\n    - Developers need to know too much math\n        - Beginners or developers without science backgrounds should be able to build quantum applications\n        - Provide advanced modules to abstract real-world problems into quantum circuits\n    - Graphical circuit builders are generally restricted to just a few hardware providers; consider building a brac-kt\n      GUI\n    - In general, lower the entry barrier for quantum\n\n## Plans\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003cth\u003eProject\u003c/th\u003e\n\u003cth\u003eDetails\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eNative backend\u003c/td\u003e\n\u003ctd\u003e\n\n- Support C/C++ for Windows/MacOS/Linux\n    - Should be easy thanks to Kotlin\n    - Will interop with native libraries!\n    - Compile into libs/DLLs\n- Better support for native applications; write a program in C#/Swift and interface with brac-kt easily\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eOther providers\u003c/td\u003e\n\u003ctd\u003e\n\n- Add support for other hardware manufacturers\n    - Rigetti, GCP, AWS, Azure, etc.\n    - Reverse-engineer APIs (double-check that bot accounts for testing aren't prohibited)\n- JavaScript difficulties\n    - JS will treat each hardware provider package's brac-kt API as a separate entity, meaning that circuits can't be\n      shared across providers. This defeats the purpose of brac-kt!\n    - Two solutions:\n        - Don't bundle API with provider packages (preferred, but harder to figure out)\n        - Build circuits using functions, where qc parameter has\n          type `provider.a.Quantum Circuit | provider.b.QuantumCircuit` (it's fine, but not as good as the first\n          solution)\n- More important later\n    - This feature will matter more when hardware providers are actually competing for market share\n    - Right now, people still need to figure out the software. The hardware selection only matters because you're locked\n      into the single hardware ecosystem, which is what brac-kt will solve\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eBetter documentation\u003c/td\u003e\n\u003ctd\u003e\n\n- In addition to the [dokka docs](https://javaman.net/brac-kt), write better documentation for utils, hardware\n  providers, examples, macros, etc.\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eAdvanced modules\u003c/td\u003e\n\u003ctd\u003e\n\n- Build modules that abstract regular problems into quantum circuits\n- Read through more online courses, textbooks, etc. to learn about real-world applications and algorithms\n- Make it easy for any developer to get started without having to know all the linalg math\n- See if QCP can be implemented; that would be a good first step\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eBasic simulator\u003c/td\u003e\n\u003ctd\u003e\n\n- Try to simulate basic quantum circuits on a Kotlin server\n    - How? I have no clue how the math works\n- Optimize heavily using a profiler\n- Will this be a commercial product? If so, I need to buy IntelliJ Ultimate\n- Kotlin/Native or Kotlin/JVM?\n    - If, somehow, this application can be CUDA-accelerated, look into Kotlin/Native interop with libs/DLLs\n    - Otherwise, Kotlin/JVM is just as easy (not in a math sense, though)\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n## Inspired By\n\n- [Qiskit](https://github.com/Qiskit)\n- [ssuukk/Qotlin](https://github.com/ssuukk/Qotlin)\n- [Antimonit/Quantum](https://github.com/Antimonit/Quantum)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenewjavaman%2Fbrac-kt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthenewjavaman%2Fbrac-kt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenewjavaman%2Fbrac-kt/lists"}