Coder Social home page Coder Social logo

rigetti / oqaml Goto Github PK

View Code? Open in Web Editor NEW
37.0 7.0 7.0 225 KB

An OCaml based implementation of a Quil QVM

License: Apache License 2.0

Makefile 3.05% OCaml 95.68% Shell 1.11% Dockerfile 0.16%
quantum-simulation ocaml functional-programming state-machine

oqaml's Introduction

Notice: This is research code that will not necessarily be maintained to support further releases of Forest and other Rigetti Software. We welcome bug reports and PRs but make no guarantee about fixes or responses.

OQaml

OQaml is licensed under the Apache 2.0 license.

Introduction

OQaml is a reference implementation of the Quantum Abstract Machine (QAM) outlined in R. Smith, M. J. Curtis and W. J. Zeng, "A Practical Quantum Instruction Set Architecture," (2016), arXiv:1608.03355 [quant-ph]. The purpose of OQaml is to demonstrate the conceptual similarities between a classical state machine and a Quantum state machine. It highlights the facts in which functional programming lends itself ideally to the operations on a quantum state as it enforces deliberate actions to force side-effects, i.e. interactions with the environment.

OQaml currently supports ProtoQuil (a subset of the full Quil instruction language) which includes one- and two-qubit gate instructions as well as a full state measurement.

Getting started

Setting up the environment

To hit the ground running to interact with OQaml you need to set up your OCaml environment as described in a short OQaml setup guide. The best way to interact with OQaml is the use of utop. A more general guide how to set up a good OCaml environment can be found in the RealWorldOCaml instructions.

OQaml actively uses Owl and JaneStreet's Core_extended. Both of which can be easily install using Opam. Note, however, that some functionality of OQaml requires the latest changes to the development branch of Owl, which is not yet available on Opam.

Installing OQaml

If you have already have a working OCaml environment you can install OQaml by cloning this repository and run.

make all
make install

from the repository root. This will install OQaml into your OCaml environment.

Interacting with the Ocaml QVM

If all functionality is installed then interactions with the OQaml QVM are best done using utop running

utop

This drops you into a OCaml REPL and you can start loading modules and interact with the QVM.

utop[0]> #require "oqaml";;
utop[1]> #require "owl";;
utop[2]> module V = Owl.Dense.Vector.C;;
module V = Owl.Dense.Vector.C
utop[3]> module Q = Oqaml;;
module Q = Oqaml
utop[4]> let tqvm = Q.init_qvm 3;;
val tqvm : Q.qvm = {Q.num_qubits = 3; wf =
        C0
R0 (1, 0i)
R1 (0, 0i)
R2 (0, 0i)
R3 (0, 0i)
R4 (0, 0i)
R5 (0, 0i)
R6 (0, 0i)
R7 (0, 0i)

;
reg = [|0; 0; 0;|]}
utop[5]> let prog = Q.CIRCUIT([Q.Y 2; Q.CNOT (0,1); Q.X 0]);;
val prog : Q.gate = Q.CIRCUIT [Q.Y 2; Q.CNOT (0, 1); Q.X 0]
utop[6]> Q.apply prog tqvm;;
- : Q.qvm = {Q.num_qubits = 3; wf =
        C0
R0 (0, 0i)
R1 (0, 0i)
R2 (0, 0i)
R3 (0, 0i)
R4 (0, 0i)
R5 (0, 0i)
R6 (0, 0i)
R7 (0, 1i)

;
reg = [|0; 0; 0;|]}

Note that the gates in the set prog are executed from right to left in the way quantum-mechanical notation acts on a state.

Walkthrough

More details can be found in the small getting started walkthrough.

Building the docs

To build the API docs you can run

make docs

This will create a subfolder containing an HTML project that exposes all public APIs of OQaml. To create the readme files and images you need the most recent development version of readme2tex; Compilation is done with

make readmes

will convert the tex markdown files to well readable markdown.

Development and Testing

The test infrastructure uses Alcotest. To run the tests you can execute

opam install alcotest
make test

How to cite OQaml

If you use the reference-qvm please cite the repository as follows:

bibTex:

@misc{oqaml2017.0.0.1,
  author = {Rigetti Computing},
  title = {OQaml},
  year = {2017},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/rigetticomputing},
  commit = {the commit you used}
}

and the paper outlining the mathematical specification of the quantum-abstract-machine:

bibTeX:

@misc{1608.03355,
  title={A Practical Quantum Instruction Set Architecture},
  author={Smith, Robert S and Curtis, Michael J and Zeng, William J},
  journal={arXiv preprint arXiv:1608.03355},
  year={2016}
}

oqaml's People

Contributors

dangirsh avatar fxfactorial avatar jotterbach avatar willzeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

oqaml's Issues

Having problems with installation

This is what I get: https://pastebin.com/qceDWNkg

(edit for readability)

vtomole@vtomole:~/oqaml$ sudo make all && make install
ocaml setup.ml -build -tag thread
Start compiling OQaml ...
+ ocamlfind ocamlopt unix.cmxa -I /home/vtomole/.opam/4.04.2/lib/ocamlbuild /home/vtomole/.opam/4.04.2/lib/ocamlbuild/ocamlbuildlib.cmxa -linkpkg myocamlbuild.ml /home/vtomole/.opam/4.04.2/lib/ocamlbuild/ocamlbuild.cmx -o myocamlbuild
File "myocamlbuild.ml", line 1:
Error: /home/vtomole/.opam/4.04.2/lib/ocamlbuild/ocamlbuild_plugin.cmi
is not a compiled interface for this version of OCaml.
It seems to be for a newer version of OCaml.
Command exited with code 2.
Compilation unsuccessful after building 1 target (0 cached) in 00:00:00.
E: Failure("Command ''/home/vtomole/.opam/4.04.2/bin/ocamlbuild' src/oqaml.cma src/oqaml.cmxa src/oqaml.a src/oqaml.cmxs -use-ocamlfind -tag debug -tag thread' terminated with error code 10")
Makefile:25: recipe for target 'all' failed
make: *** [all] Error 1

Avoid using pointer equality

Not sure if this was intent, but usually isn't:

let cand x y arr =
  let bit_and ctr tar = if (ctr == 1 && tar == 1) then 1 else 0 in
  arr.(y) <-  bit_and arr.(x) arr.(y);
  arr

let cor x y arr =
  let bit_or ctr tar = if (ctr == 0 && tar == 0) then 0 else 1 in
  arr.(y) <- bit_or arr.(x) arr.(y);
  arr

let xor x y arr =
  let bit_xor ctr tar = if (ctr == tar) then 0 else 1 in
  arr.(y) <- bit_xor arr.(x) arr.(y);
  arr

== is pointer quality , you probably wanted =

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.