Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/qkoPublic

A kotlin quantum framework

License

NotificationsYou must be signed in to change notification settings

Dpbm/qko

Repository files navigation

A quantum library for Kotlin

build and test workflowrelease and publish workflowtest publish workflow

Qko is an open source library for creating quantum circuits and executing them easily.

Its usage is inspired byQiskit andCirq. So creating your own circuit must be easy as using one of the mainstream frameworks.

Install

First of all, create a newGradle + Kotlin project.

mkdir new_projectcd new_projectgradle init

Then add to yourbuild.gradle.kts:

dependencies {    implementation("io.github.dpbm:qko:1.0")}

After that you're free to start creating your circuits.

Create circuits

For instance, to Create a Bell State, just run:

packageexamplesimportCircuitimportproviders.Outcomeimportproviders.local.LocalBackendimportproviders.local.gates.Himportproviders.local.gates.CNOTfunmain(){val circuit=Circuit(2)//circuit with 2 qubits    circuit.addGate(H(arrayListOf(0)))// add an H gate on qubit 0    circuit.addGate(CNOT(arrayListOf(0,1)))// add a CNOT between qubits 1 and 0val backend=LocalBackend()val result:Outcome= backend.execute(circuit)// execute the jobprintln("---OUTPUT---")for((index,prob)in result.toDist().withIndex()){// map through your probabilities distributionval binaryRep= index.toString(radix=2).padStart(2,'0')println("$binaryRep$prob")    }}

In this framework, we've chosen to follow the big-endian pattern, so the less significant qubit is the first from the left to the right ($q_{0}q_{1}q_{3}\ldots q_{n-1}$). This choice implies on the final bitstrings sequence, for example, applying$X(q_{0})$ changes$00$ to$10$ instead of$01$. For some people, it may seem as a problem, but in practice it's easy to remap to little-endian just flipping the sequence and its easier to think during the gates implementation. Also, in the near future, a method will be added to apply the remapping with ease.


[8]ページ先頭

©2009-2025 Movatter.jp