← Quantum Store · Guides · Lessons · Glossary · Packages · About · Türkçe

Rigetti Computing

pyQuil and Quil starter package

SoftwareQuantum SDKLicence: Apache-2.0Version: 4.22.08.0 KB

Official source: rigetti/pyquil

Download ZIP (free)

pyQuil, the Python library for Rigetti's Quil instruction set: a tested example that generates a Bell program as Quil, and a guide to running it with the local QVM.

What is pyQuil?

pyQuil is the Python library for writing programs in Quil, Rigetti's quantum instruction set. Quil is a low-level language that defines classical and quantum operations in the same program.

When to use it

The example in this package

quil_programi.py builds the Bell program and prints its Quil text. Since compiling and running the program needs two separate servers, the example only builds the program.

Running the program

Start Rigetti's quilc (compiler) and qvm (simulator) servers with Docker:

docker run --rm -it -p 5555:5555 rigetti/quilc -R
docker run --rm -it -p 5000:5000 rigetti/qvm -S

Then in Python:

from pyquil import get_qc
qc = get_qc("2q-qvm")
result = qc.run(qc.compile(p))
print(result.get_register_map()["ro"])

Installation and running

pip install pyquil
python quil_programi.py

Tested with: pyquil 4.22.0, Python 3.12.

Official source

Links

Package contents

Licence

The example code and the guide in this package were written by the Quantum Store editors and are MIT licensed. The project it uses is subject to its own licence (Apache-2.0).


Quantum Store — https://hakanerdogan.com/en

Example code

The example shipped in the package, run and checked. Comments and printed messages are in Turkish; the code is the same in any language. Everything is in the ZIP.

quil_programi.py

"""pyQuil ile Quil programı yaz.

Bu örnek programı oluşturur ve Quil metnini yazdırır. Çalıştırmak için
Rigetti'nin quilc derleyicisi ve qvm simülatörü gerekir (README'ye bakın).

Çalıştırma:
    pip install pyquil
    python quil_programi.py
"""

from pyquil import Program
from pyquil.gates import CNOT, H, MEASURE

p = Program()
ro = p.declare("ro", "BIT", 2)
p += H(0)
p += CNOT(0, 1)
p += MEASURE(0, ro[0])
p += MEASURE(1, ro[1])
p.wrap_in_numshots_loop(1000)

quil = p.out()
print(quil)
assert "CNOT 0 1" in quil and "MEASURE 1 ro[1]" in quil
print("Tamam: Quil programı oluşturuldu.")

← All packages

Share: X · LinkedIn