Giter Site home page Giter Site logo

pyquil's Introduction

pyQuil

A library for easily generating Quil programs to be executed using the Rigetti Forest platform. pyQuil is licensed under the Apache 2.0 license.

Build Status Documentation Status

Documentation

Documentation is hosted at http://pyquil.readthedocs.io/en/latest/

Installation

You can install pyQuil directly from the Python package manager pip using:

pip install pyquil

To instead install pyQuil from source, clone this repository, cd into it, and run:

pip install -e .

This will also install pyQuil's dependencies (requests >= 2.4.2 and NumPy >= 1.10) if you do not already have them.

Connecting to the Rigetti Forest

pyQuil can be used to build and manipulate Quil programs without restriction. However, to run programs (e.g., to get wavefunctions, get multishot experiment data), you will need an API key for Rigetti Forest. This will allow you to run your programs on the Rigetti Quantum Virtual Machine (QVM) or on a real quantum processor (QPU).

Once you have your key, you need to set up configuration in the file .pyquil_config which pyQuil will attempt to find in your home directory by default. (You can change this location by setting the environment variable PYQUIL_CONFIG to the path of the file.) Loading the pyquil.api module will print a warning if this is not found. The configuration file is in INI format and should contain all the information required to connect to Forest:

[Rigetti Forest]
url: <URL to Rigetti Forest or QVM endpoint>
key: <Rigetti Forest API key>
user_id: <Rigetti Forest User ID>

If url is not specified, it will default to https://api.rigetti.com/qvm.

Alternatively, you may create the .pyquil_config automatically by running the following command, which will prompt you for the required information (URL, key, and user id). The script will then create a file in the proper location (the user's root directory):

pyquil-config-setup

Examples using the Rigetti QVM

Here is how to construct a Bell state program and how to compute the amplitudes of its wavefunction:

>>> import pyquil.quil as pq
>>> import pyquil.api as api
>>> from pyquil.gates import *
>>> qvm = api.SyncConnection()
>>> p = pq.Program(H(0), CNOT(0,1))
<pyquil.pyquil.Program object at 0x101ebfb50>
>>> qvm.wavefunction(p)[0]
[(0.7071067811865475+0j), 0j, 0j, (0.7071067811865475+0j)]

How to do a simulated multishot experiment measuring qubits 0 and 1 of a Bell state. (Of course, each measurement pair will be 00 or 11.)

>>> import pyquil.quil as pq
>>> import pyquil.api as api
>>> from pyquil.gates import *
>>> qvm = api.SyncConnection()
>>> p = pq.Program()
>>> p.inst(H(0),
...        CNOT(0, 1),
...        MEASURE(0, 0),
...        MEASURE(1, 1))
<pyquil.pyquil.Program object at 0x101ebfc50>
>>> print p
H 0
CNOT 0 1
MEASURE 0 [0]
MEASURE 1 [1]

>>> qvm.run(p, [0, 1], 10)
[[0, 0], [1, 1], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [0, 0], [0, 0]]

Building the Docs

We use sphinx to build the documentation. To do this, navigate into pyQuil's top-level directory and run:

sphinx-build -b html docs/source docs/_build

To view the docs navigate to the newly-created docs/_build directory and open the index.html file in a browser. Note that we use the Read the Docs theme for our documentation, so this may need to be installed using pip install sphinx_rtd_theme.

Development and Testing

We use pytest (version > 3.0) and mock for testing. Tests can be run from the top-level directory using:

python setup.py test

If you want to test in multiple enviornments, such as Python 2.7 and Python 3.6, then you can use tox. This is done with:

pip install tox
tox

How to cite pyQuil and Forest

If you use pyQuil, Grove, or other parts of the Rigetti Forest stack in your research, please cite it as follows:

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}
}

Text:

R. Smith, M. J. Curtis and W. J. Zeng, "A Practical Quantum Instruction Set Architecture," (2016), 
  arXiv:1608.03355 [quant-ph], https://arxiv.org/abs/1608.03355

pyquil's People

Contributors

ampolloreno avatar balopat avatar caryan avatar echelon9 avatar harleypatton avatar jotterbach avatar karalekas avatar mpharrigan avatar ncrubin avatar ntezak avatar rallim avatar stylewarning avatar vontell avatar willzeng avatar

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.