Skip to content

Dpbm/qko

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Jan 28, 2025
a0a5998 · Jan 28, 2025

History

81 Commits
Jan 28, 2025
Jan 9, 2025
Jan 28, 2025
Jan 8, 2025
Jan 26, 2025
Jan 8, 2025
Jan 28, 2025
Jan 28, 2025
Jan 28, 2025
Jan 8, 2025
Jan 8, 2025
Jan 8, 2025
Jan 28, 2025
Jan 8, 2025

Repository files navigation

QKO

A quantum library for Kotlin

build and test workflow release and publish workflow test publish workflow

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

Its usage is inspired by Qiskit and Cirq. So creating your own circuit must be easy as using one of the mainstream frameworks.

Install

First of all, create a new Gradle + Kotlin project.

mkdir new_project
cd new_project
gradle init

Then add to your build.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:

package examples

import Circuit
import providers.Outcome
import providers.local.LocalBackend
import providers.local.gates.H
import providers.local.gates.CNOT

fun main(){
    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 0

    val backend = LocalBackend()
    val result:Outcome = backend.execute(circuit) // execute the job

    println("---OUTPUT---")

    for((index,prob) in result.toDist().withIndex()){ // map through your probabilities distribution
        val 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 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.