Skip to main content

A Python library to generate Quantum Instruction Language (Quil) Programs.

Project description

# 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](https://github.com/rigetticomputing/pyQuil/blob/master/LICENSE).

[![Build Status](https://semaphoreci.com/api/v1/rigetti/pyquil/branches/master/badge.svg)](https://semaphoreci.com/rigetti/pyquil)
[![Documentation Status](https://readthedocs.org/projects/pyquil/badge/?version=latest)](http://pyquil.readthedocs.io/en/latest/?badge=latest)

## Documentation

Documentation is hosted at [http://pyquil.readthedocs.io/en/latest/](http://pyquil.readthedocs.io/en/latest/)

## Installation

You can install pyQuil as a conda package (recommended):

```bash
conda install -c rigetti pyquil
```

or using `pip`:

```
pip install pyquil
```

To instead install pyQuil from source, clone this repository, `cd` into it, and run:
```
pip install -e .
```

## Connecting to 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](http://forest.rigetti.com). 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, run the following command to automatically set up your config:

```
pyquil-config-setup
```

You can also create the configuration file manually if you'd like and place it at `~/.pyquil_config`.
The configuration file is in INI format and should contain all the information required to connect to Forest:

```
[Rigetti Forest]
key: <Rigetti Forest API key>
user_id: <Rigetti User ID>
```

You can change the location of this file by setting the `PYQUIL_CONFIG` environment variable.

If you encounter errors or warnings trying to connect to Forest then see the full
[Getting Started Guide](https://go.rigetti.com/getting-started)

## Examples using the Rigetti QVM

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

```python
>>> from pyquil.quil import Program
>>> from pyquil.api import QVMConnection
>>> from pyquil.gates import *
>>> qvm = QVMConnection()
>>> p = Program(H(0), CNOT(0,1))
<pyquil.pyquil.Program object at 0x101ebfb50>
>>> qvm.wavefunction(p).amplitudes
array([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`.)

```python
>>> from pyquil.quil import Program
>>> from pyquil.api import QVMConnection
>>> from pyquil.gates import *
>>> qvm = QVMConnection()
>>> p = 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]]
```

## Community

Join the public Forest Slack channel at [http://slack.rigetti.com](http://slack.rigetti.com).

The following projects have been contributed by community members:

- [Syntax Highlighting for Quil](https://github.com/JavaFXpert/quil-syntax-highlighter)
contributed by [James Weaver](https://github.com/JavaFXpert)
- [Web Based Circuit Simulator](https://github.com/rasa97/quil-sim/tree/master)
contributed by [Ravisankar A V](https://github.com/rasa97)
- [Quil in Javascript](https://github.com/mapmeld/jsquil)
contributed by [Nick Doiron](https://github.com/mapmeld)
- [Quil in Java](https://github.com/QCHackers/jquil)
contributed by [Victory Omole](https://github.com/vtomole)

## Developing PyQuil

To make changes to PyQuil itself see [DEVELOPMENT.md](DEVELOPMENT.md) for instructions on development and testing.

## 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
```

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyquil-2.0.0b6.tar.gz (115.7 kB view details)

Uploaded Source

File details

Details for the file pyquil-2.0.0b6.tar.gz.

File metadata

  • Download URL: pyquil-2.0.0b6.tar.gz
  • Upload date:
  • Size: 115.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.6

File hashes

Hashes for pyquil-2.0.0b6.tar.gz
Algorithm Hash digest
SHA256 7cc86173d6ab6749f4e6052c8cee9f861e6d7776378de0266652af132ec2c438
MD5 74f09e4ae2908bdd7bb37c266847e822
BLAKE2b-256 702d2981cf92be5229e4c17cbb1ea3c80a95cfd8d480d732cfa6b168d1665992

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page