Python Other
Clone or download
mpharrigan Move the borders between qpu and qvm (#504)
* Factor endpoints

* WavefunctionSimulator

* Factor out ForestConnection

* `QVM`

* `QPU`

* Remove `device` (and compilation) from `QVM`

* Remove `device` (and compilation) from `QPU`

* Just make `expectation` on new `WavefunctionSimulator` do what we want

* Make a QAM

* Create and wrap `AbstractDevice` abstraction

* Add `QuantumComputer` abstraction

* Refactor default classical_addresses to `QuantumComputer`

* Make ForestConnection methods private

*  Remove duplicate code from QPUConnection while maintaining backcompat

* Remove duplicate code from QVMConnection while maintaining backcompat

Left a whole bunch of code since some of the functionality changed.
Particularly, the new API removes the ability to set
needs_compilation=True for all of the wavefunction-based methods

* Slight usability improvements

* nit

* remove unused code

* Docstrings

* Use abstractmethod

* Don't need `pass` with docstrings

* Clarify developer note and dont poo-poo new run_and_measure

* device is not optional

* Fix _get_flipped_program with all measure instructions

* abstractmethod

* rename `symmetrize_readout`

* Consistent docstrings for run

* Just `device_name`

* Include QAM in __init__

* Tests

* wait_for_job docstrings

* nit

* Return type annotation

* Return type annotation

* Use numpy

* Robust switch to numpy arrays

Cast to numpy as early as possible. Old QXXConnection methods
cast back to lists for backwards-compatibility

A break in backwards compatibility occurs with job.result() which
now gives you numpy arrays.

* flake8

* py35 unordered dictionaries
Latest commit a972b2f Jul 20, 2018

README.md

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 .

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

Examples using the Rigetti QVM

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

>>> 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.)

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

The following projects have been contributed by community members:

Developing PyQuil

To make changes to PyQuil itself see 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