Package: pyquil
PyQuil: Quantum programming in PythonPyQuil is a Python library for quantum programming usingQuil,
the quantum instruction language developed atRigetti Computing.
PyQuil serves three main functions:Easily generating Quil programs from quantum gates and classical operationsCompiling and simulating Quil programs using theQuil Compiler(quilc) and theQuantum Virtual Machine(QVM)Executing Quil programs on real quantum processors (QPUs) usingQuantum Cloud Services(QCS)PyQuil has a ton of other features, which you can learn more about in thedocs. However, you can also keep reading
below to get started with running your first quantum program!Quickstart with interactive tutorial notebooksWithout installing anything, you can quickly get started with quantum programming by exploring
our interactiveJupyternotebook tutorials and examples. To run them in a preconfigured
execution environment onBinder, click the "launch binder" badge at the top of the
README or the linkhere! To learn more about the tutorials and how you can add your own,
visit therigetti/forest-tutorialsrepository. If you'd rather set everything
up locally, or are interested in contributing to pyQuil, continue onto the next section for
instructions on installing pyQuil and the Forest SDK.Installing pyQuil and the Forest SDKPyQuil can be installed usingconda,pip, or from source. To install it from PyPI (viapip),
do the following:pipinstallpyquilTo instead install pyQuil from source, do the following from within the repository after cloning it:pipinstall-e.If you choose to usepip, we highly recommend installing pyQuil within a virtual environment.PyQuil, along with quilc, the QVM, and other libraries, make up what is called the Forest
SDK. To make full use of pyQuil, you will need to additionally have installedquilcand theQVM.
For more information, check out the docs!Running your first quantum programIn just a few lines, we can use pyQuil with the Forest SDK to simulate a Bell state!frompyquilimportget_qc,Programfrompyquil.gatesimportCNOT,H,MEASUREqvm=get_qc('2q-qvm')p=Program()p+=H(0)p+=CNOT(0,1)ro=p.declare('ro','BIT',2)p+=MEASURE(0,ro[0])p+=MEASURE(1,ro[1])p.wrap_in_numshots_loop(10)qvm.run(p).get_register_map()['ro'].tolist()The output of the above program should look something like the following,
the statistics of which are consistent with a two-qubit entangled state.[[0, 0],
 [1, 1],
 [1, 1],
 [1, 1],
 [1, 1],
 [0, 0],
 [0, 0],
 [1, 1],
 [0, 0],
 [0, 0]]Using the Forest SDK, you can simulate the operation of a real quantum processor (QPU). If you
would like to run on the real QPUs in our lab in Berkeley, you can sign up for an account
onQuantum Cloud Services(QCS)!Joining the Forest communityIf you'd like to get involved with pyQuil and Forest, joining theRigetti Forest Slack Workspaceis a great place to start! You can do so by
clicking the invite link in the previous sentence, or in the badge at the top of this README.
The Slack Workspace is a great place to ask general questions, join high-level design discussions,
and hear about updates to pyQuil and the Forest SDK.To go a step further and start contributing to the development of pyQuil, good first steps arereporting a bug,requesting a feature, or picking up one of the issues with thegood first issueorhelp wantedlabels. Once you find an issue to work
on, make sure tofork this repositoryand thenopen a pull requestonce your changes
are ready. For more information on all the ways you can contribute to pyQuil (along with
some helpful tips for developers and maintainers) check out ourContributing Guide!To see what people have contributed in the past, check out theChangelogfor
a detailed list of all announcements, improvements, changes, and bugfixes. TheReleasespage for pyQuil contains similar
information, but with links to the pull request for each change and its corresponding author.
Thanks for contributing to pyQuil! 🙂Citing pyQuil, Forest, and Quantum Cloud ServicesIf you use pyQuil, Grove, or other parts of the Forest SDK in your research, please cite
theQuil specificationusing the following BibTeX snippet:@misc{smith2016practical,title={A Practical Quantum Instruction Set Architecture},author={Robert S. Smith and Michael J. Curtis and William J. Zeng},year={2016},eprint={1608.03355},archivePrefix={arXiv},primaryClass={quant-ph}}Additionally, if your research involves taking data on Rigetti quantum processors (QPUs) via
the Quantum Cloud Services (QCS) platform, please reference theQCS paperusing the
following BibTeX snippet:@article{Karalekas_2020,title={A quantum-classical cloud platform optimized for variational hybrid algorithms},author={Peter J Karalekas and Nikolas A Tezak and Eric C Petersonand Colm A Ryan and Marcus P da Silva and Robert S Smith},year=2020,month={apr},publisher={{IOP} Publishing},journal={Quantum Science and Technology},volume={5},number={2},pages={024003},doi={10.1088/2058-9565/ab7559},url={https://doi.org/10.1088%2F2058-9565%2Fab7559},}The preprint of the QCS paper is available onarXiv, and the supplementary
interactive notebooks and datasets for the paper can be found in therigetti/qcs-paperrepository.LicensePyQuil is licensed under theApache License 2.0.