Git Product home page Git Product logo

quantumlisp's Introduction

QuantumLisp

Quantum computing simulator for Common Lisp.

Examples

Creating and printing a superposition:

(defvar qubits (quantumlisp:superpos (list 1 0)))
(quantumlisp:print-superpos qubits)

Applying different quantum gates to a superposition:

(setq qubits (quantumlisp:swap qubits))
(setq qubits (quantumlisp:sqrt-swap qubits))
(setq qubits (quantumlisp:cnot qubits))

Collapsing a superposition:

(quantumlisp:collapse qubits)

Getting Started

An installation of the Quicklisp package manager is required

(push #p"/YOUR/CLONE/PATH/QuantumLisp/" asdf:*central-registry*)
(ql:quickload "quantumlisp")

License

MIT

quantumlisp's People

Contributors

fwcd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jgarte

quantumlisp's Issues

Tensor multiplication and factorization

Implement tensor multiplication and factorization to operate separately on qubit superpositions.

Currently an array of 3 qubits (thus a vector of 2^3 = 8 possible states) can only be used to apply three-qubit-gates (CCNOT or CSWAP), because the matrix representing the gate has to have the same side length as the superposition vector. To allow 1-qubit-gates (like the Pauli-X gate) to operate on multiple qubits, the tensor product is necessary to appropriately modify the gate matrix.

Still, the size of the superposition vector will grow exponentially to the amount of qubits. As long as these qubits are not entangled, they could be treated (and measured) separately. To implement this, tensor factorization is required.

Kronecker product & new (superpos)

Below is some quick code I've put together while playing with this library. I've just started reading up on Quantum computing, so I'm not 100% clear on how the kronecker product is to be applied when working with a subset of qubits, but I've validated that it works properly for the spanning/parallel case. I.e. apply-qgate with H*H matrix works properly for the Hadamard to a two-qubit pair.

; More efficient construction of the superposition. On my test system constructing a 14-bit
; superposition takes 3.5 seconds with the original code. This code takes 3 milliseconds.
(defun superpos (bits &optional (zero 0))
(let ((outrep (make-list (expt 2 (length bits)) :initial-element zero))
(index (reduce (lambda (current previous) (+ (* current 2) previous)) bits)))
(setf (elt outrep index) (+ zero 1))
outrep))

; Kronecker / tensor product
(defun kronecker-product(A B)
(matrix-create
(lambda (i j)
(let ((p (matrix-row-count B))
(q (matrix-column-count B)))
(* (elt (elt A (floor i p)) (floor j q))
(elt (elt B (mod i p)) (mod j q)))))
(* (matrix-row-count A) (matrix-row-count B))
(* (matrix-column-count A) (matrix-column-count B))))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.