A Kotlin/Multiplatform interface for quantum computing |
|
Named after bra-ket quantum notation (with "kt" for Kotlin), pronounced "bracket" |
Write quantum circuits in any major language:
Java Virtual Machine | JavaScript Runtimes (Browser, Node.js) | Native Platforms (Windows, Linux) |
---|---|---|
|
|
|
The brac-kt API will be included with any providers you install.
Add to build.gradle.kts
:
repositories {
mavenCentral()
maven {
url = uri("https://jitpack.io")
}
}
dependencies {
implementation("net.javaman.brac-kt:brac-kt-ibmq-provider")
}
Install via npm
:
npm i @thenewjavaman/brac-kt-ibmq-provider
Download from the releases page.
You'll need libcurl. It's on most Linux installations by default, or you can get it on MinGW (Windows) through pacman
.
object Application {
init {
BracKtApi.addInjections()
IbmqProvider.addInjections()
}
private val propertyManager: PropertyManager by injection()
private val ibmqProvider: IbmqProvider by injection()
@JvmStatic
fun main(args: Array<String>) {
val n = 3
val qc = QuantumCircuit(name = "Example Superposition", numQubits = 3) {
repeat(n) { h(qubit = it) }
repeat(n) { measure(qubit = it, bit = it) }
}
val apiToken: String = propertyManager["IBMQ_API_TOKEN"]
ibmqProvider.logInSync(apiToken)
ibmqProvider.selectNetworkSync()
ibmqProvider.selectDeviceSync()
ibmqProvider.runExperimentAndWaitSync(qc)
}
}
public class Application {
static {
BracKtApi.addInjections();
IbmqProvider.addInjections();
}
private static final IbmqProvider ibmqProvider = new IbmqProvider();
public static void main(String[] args) {
int n = 3;
QuantumCircuit qc = new QuantumCircuit("Example Superposition", n);
for (int i = 0; i < n; i++) qc.h(i);
for (int i = 0; i < n; i++) qc.measure(i, i);
String apiToken = System.getenv("IBMQ_API_TOKEN");
ibmqProvider.logInSync(apiToken);
ibmqProvider.selectNetworkSync();
ibmqProvider.selectDeviceSync();
ibmqProvider.runExperimentAndWaitSync(qc);
}
}
const app = async () => {
bracKt.api.addInjections();
bracKt.providers.ibmq.addInjections();
const n = 3;
const qc = new QuantumCircuit("Example Superposition", 3);
for (let i = 0; i < n; i++) qc.h(i);
for (let i = 0; i < n; i++) qc.measure(i, i);
const ibmqProvider = new IbmqProvider();
await ibmqProvider.logInAsync(process.env.IBMQ_API_TOKEN);
await ibmqProvider.selectNetworkAsync();
await ibmqProvider.selectDeviceAsync();
await ibmqProvider.runExperimentAndWaitAsync(qc);
};
int main(int argc, char **argv) {
BracKt *bracKt = libbrac_kt_ibmq_provider_symbols();
bracKt->api.addInjections();
bracKt->ibmq_provider.addInjections();
int n = 3;
QuantumCircuit qc = bracKt->api.quantum.QuantumCircuit.QuantumCircuit_("Example Superposition", n, n);
for (int i = 0; i < n; i++) bracKt->api.quantum.QuantumCircuit.h(qc, i);
for (int i = 0; i < n; i++) bracKt->api.quantum.QuantumCircuit.measure(qc, i, i);
IbmqProvider ibmqProvider = bracKt->ibmq_provider.IbmqProvider.IbmqProvider();
bracKt->ibmq_provider.IbmqProvider.logInSync(ibmqProvider, getenv("IBMQ_API_TOKEN"));
bracKt->ibmq_provider.IbmqProvider.selectNetworkSync(ibmqProvider);
bracKt->ibmq_provider.IbmqProvider.selectDeviceSync_(ibmqProvider, true, n);
bracKt->ibmq_provider.IbmqProvider.runExperimentAndWaitSync(ibmqProvider, qc);
}
Every example outputs:
...
[...] [INFO ] Qubit outcomes:
[...] [INFO ] 0x0: 0.12890625 (132/1024)
[...] [INFO ] 0x1: 0.12792969 (131/1024)
[...] [INFO ] 0x2: 0.13769531 (141/1024)
[...] [INFO ] 0x3: 0.12695312 (130/1024)
[...] [INFO ] 0x4: 0.1171875 (120/1024)
[...] [INFO ] 0x5: 0.12109375 (124/1024)
[...] [INFO ] 0x6: 0.109375 (112/1024)
[...] [INFO ] 0x7: 0.13085938 (134/1024)
Integrating with other languages is seamless because brac-kt compiles into Java bytecode and JavaScript with TypeScript definitions. Additionally, each platform has its own unique features; for example, Java and C/C++ have additional synchronous API methods, whereas JavaScript has async/await versions. Kotlin on all platforms gets a few unique features: a cross-platform property manager, dependency injection, and all-around cleaner syntax.
What am I trying to accomplish?
- Write quantum circuits once, run on any hardware
- Write quantum circuits in any major language using the same library (see Support above)
- Simplify the quantum development process
- Write quantum circuits once, run on any hardware
- Each hardware provider provides their own tools, which can't cross-compile
- Make it easy to test on different providers
- Make it easy to switch providers when new features become available
- Write quantum circuits in any major language using the same library
- Replace standard Python libraries with a pure Kotlin/Multiplatform implementation
- Python has many limitations:
- Restricted to only the Python runtime
- Not type-safe, null-safe; prone to runtime errors
- Slow for non-C implementations; limits choices for big projects
- Not well-adopted outside of data science
- Kotlin fixes these issues:
- Can run on the JVM, JS (browser or node.js), and native runtimes
- Type-safe, null-safe; compile-time checks safeguard the development process
- Very performant, especially for server applications on the JVM
- Can run on any major runtime, so it can interop with most popular libraries
- JVM: Desktop applications, servers
- JS: Desktop apps, websites, sometimes servers (although they're less performant)
- Native: Desktop applications, interop with legacy/low-level software, workstations tasks (scientific research)
- Python has many limitations:
- Easy to develop fullstack apps using one library in both frontend and backend
- Provides more options for beginners, easier for people with non-data science backgrounds
- Replace standard Python libraries with a pure Kotlin/Multiplatform implementation
- Simplify quantum development process
- Developers need to know too much math
- Beginners or developers without science backgrounds should be able to build quantum applications
- Provide advanced modules to abstract real-world problems into quantum circuits
- Graphical circuit builders are generally restricted to just a few hardware providers; consider building a brac-kt GUI
- In general, lower the entry barrier for quantum
- Developers need to know too much math
Project | Details |
---|---|
Native backend |
|
Other providers |
|
Better documentation |
|
Advanced modules |
|
Basic simulator |
|