Skip to content

Commit

Permalink
feat(py): Add waveforms module for generating discrete IQ value seque…
Browse files Browse the repository at this point in the history
…nces representing Quil's defined set of waveforms. (#399)

* feat(py): Add `waveforms` module for generating discrete IQ value sequences representing Quil's defined set of waveforms.

* waveform->waveforms to match Rust crate

* replace uv with poetry, other cleanups

* remove unneeded tasks

* add dependency to test task

* fix apply_phase_and_detuning

* fix pyproject version
  • Loading branch information
MarquessV authored Sep 20, 2024
1 parent a0f2776 commit 3306782
Show file tree
Hide file tree
Showing 19 changed files with 505 additions and 84 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/msrv.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Based on https://github.com/actions-rs/meta/blob/master/recipes/msrv.md

on:
on:
push:
branches: [main]
pull_request:
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
override: true
- uses: davidB/rust-cargo-make@v1
- uses: actions/checkout@v1
- uses: snok/install-poetry@v1
- uses: syphar/restore-virtualenv@v1
- name: Run quil-py tests, lints, and formatting checks.
run: cargo make --cwd quil-py

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install poetry
uses: snok/install-poetry@v1
- uses: Swatinem/rust-cache@v2
- name: Install cargo-make
uses: actions-rs/cargo@v1
with:
command: install
args: --debug cargo-make
- uses: syphar/restore-virtualenv@v1
- name: Build quil-py documentation
uses: actions-rs/cargo@v1
with:
Expand Down
15 changes: 8 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions quil-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ numpy = "0.20.0"
pyo3 = { version = "0.20.3", features = ["indexmap"] }
rigetti-pyo3 = {version = "0.3.4", features = ["indexmap"]}
indexmap.workspace = true
num-complex = "0.4.6"

[build-dependencies]
pyo3-build-config = "0.20.0"
104 changes: 59 additions & 45 deletions quil-py/Makefile.toml
Original file line number Diff line number Diff line change
@@ -1,65 +1,79 @@
[env]
PYTHONPATH = { script = [ "python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'" ] }
RUST_BACKTRACE = 0

[tasks.poetry-install]
command = "poetry"
args = ["install"]

[tasks.install-quil]
command = "poetry"
args = ["run", "maturin", "develop"]

[tasks.stubtest]
dependencies = ["poetry-install"]
command = "poetry"
args = ["run", "stubtest", "--allowlist", ".stubtest-allowlist", "quil"]

[tasks.stubtest-flow]
dependencies = [
"poetry-install",
"install-quil",
"stubtest",
[tasks.check-venv]
description = "Check if a virtual environment is activated"
script = [
'''
if [ -z "$VIRTUAL_ENV" ]; then
echo "No virtual environment activated. Please activate one."
exit 1
else
echo "Virtual environment is active."
fi
'''
]

[tasks.format]
dependencies = ["poetry-install"]
command = "poetry"
args = ["run", "ruff", "format"]
[tasks.install-uv]
dependencies = ["check-venv"]
description = "Install dependencies using uv"
command = "pip"
args = ["install", "uv"]

[tasks.check-format]
dependencies = ["poetry-install"]
command = "poetry"
args = ["run", "ruff", "format", "--check"]
[tasks.install-deps]
dependencies = ["install-uv"]
description = "Install project dependencies using uv."
script = [
'''
uv pip compile pyproject.toml --all-extras > requirements-dev.txt
uv pip install -r requirements-dev.txt
rm requirements-dev.txt
'''
]

[tasks.lint]
dependencies = ["poetry-install"]
command = "poetry"
args = ["run", "ruff", "check"]
[tasks.install-python-package]
dependencies = ["check-venv", "install-deps"]
description = "Build the python package and install to the active virtual environment."
command = "maturin"
args = ["develop"]

[tasks.pytest]
command = "poetry"
args = ["run", "pytest"]
[tasks.test]
dependencies = ["install-python-package"]
command = "pytest"
args = ["tests_py"]

[tasks.pytest-flow]
dependencies = [
"poetry-install",
"install-quil",
"pytest",
"install-python-package",
"test",
"post-test",
]

[tasks.docs]
dependencies = ["poetry-install", "install-quil"]
command = "poetry"
args = ["run", "pdoc", "-o", "build/docs", "quil", "!quil.quil", "--logo", "https://qcs.rigetti.com/static/img/rigetti-logo.svg"]
[tasks.stubtest]
command = "stubtest"
args = [
"--allowlist",
".stubtest-allowlist",
"quil"
]

[tasks.dev-flow]
[tasks.stubtest-flow]
dependencies = [
"dev-test-flow",
"pytest-flow",
"install-python-package",
"stubtest",
"lint",
"check-format"
]

[tasks.dev-flow]
dependencies = ["dev-test-flow", "pytest-flow", "stubtest"]

[tasks.default]
alias = "dev-flow"

[tasks.ci-flow]
dependencies = ["pytest-flow", "stubtest"]

[tasks.docs]
dependencies = ["install-python-package"]
command = "pdoc"
args = ["-o", "build/docs", "quil", "!quil.quil", "--logo", "https://qcs.rigetti.com/static/img/rigetti-logo.svg"]
42 changes: 18 additions & 24 deletions quil-py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[project]
name = "quil"
version = "0.12.1"
requires-python = ">=3.8"
description = "A Python package for building and parsing Quil programs."
documentation = "https://rigetti.github.io/quil-rs/quil.html"
Expand All @@ -14,34 +15,24 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Operating System :: OS Independent",
]

# PEP 621 specifies the [project] table as the source for project metadata. However, Poetry only supports [tool.poetry]
# We can remove this table once this issue is resolved: https://github.com/python-poetry/poetry/issues/3332
[tool.poetry]
name = "quil"
version = "0.12.1"
description = "A Python package for building and parsing Quil programs."
readme = "README-py.md"
authors = ["Rigetti Computing <softapps@rigetti.com>"]

[tool.poetry.dependencies]
python = "^3.8"
numpy = "^1.21"

[tool.poetry.group.dev.dependencies]
ruff = "^0.3.7"
maturin = "^1.2.3"
mypy = "^1.1.1"
pytest = "^7.2.2"
pdoc = "^14.1.0"
syrupy = "^3.0.6"
dependencies = ["numpy>=1.2.1"]

[tool.maturin]
features = ["pyo3/extension-module"]
bindings = "pyo3"
compatibility = "linux"
sdist-include = ["README.md"]

[project.optional-dependencies]
dev = [
"ruff>=0.3.7",
"maturin>=1.2.3",
"mypy>=1.1.1",
"pytest>=7.2.2",
"pdoc>=14.1.0",
"syrupy>=3.0.6"
]

[build-system]
requires = ["maturin>=1.0.0,<2.0.0"]
build-backend = "maturin"
Expand Down Expand Up @@ -83,7 +74,7 @@ target-version = "py38"
select = ["D", "E4", "E7", "E9", "F", "I", "B", "S", "W"]
ignore = [
"E741" # "Ambiguous" variable names like "I" aren't ambiguous in this contex.
]
]
fixable = ["ALL"]
unfixable = []
# Allow unused variables when underscore-prefixed.
Expand All @@ -93,8 +84,8 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
"quil/**/*.py" = [
"F403", # * imports allowed in extension module glue.
"D100", # docstrings belong in type stubs
"D104",
]
"D104",
]
"test/**/*.py" = [
"D", # docstrings are not enforced in tests
"S101", # asserts are allowed in tests
Expand All @@ -116,6 +107,9 @@ convention = "google"
# necessarily the case for a pure Rust pyo3 module, so disabling it.
reportMissingModuleSource = false

[tool.mypy]
plugins = "numpy.typing.mypy_plugin"

[[tool.mypy.overrides]]
module = [
"quil.quil",
Expand Down
2 changes: 1 addition & 1 deletion quil-py/quil/instructions/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ class Gate:
equal the number of existing parameters.
"""
...
def to_unitary_mut(self, n_qubits: int) -> NDArray[np.complex_]:
def to_unitary_mut(self, n_qubits: int) -> NDArray[np.complex128]:
"""Lift a Gate to the full `n_qubits`-qubit Hilbert space.
Returns a ``GateError` if any of the parameters of this gate are
Expand Down
4 changes: 3 additions & 1 deletion quil-py/quil/program/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""The `quil.program` module contains classes for constructing and representing a Quil program."""
"""The `quil.program` module contains classes for constructing and representing a
Quil program.
"""

from quil.program import *
2 changes: 1 addition & 1 deletion quil-py/quil/program/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Program:
Raises a ``ProgramError`` if the given string isn't valid Quil.
"""
def to_instructions(self) -> Sequence[Instruction]: ...
def to_unitary(self, n_qubits: int) -> NDArray[np.complex_]: ...
def to_unitary(self, n_qubits: int) -> NDArray[np.complex128]: ...
def copy(self) -> "Program":
"""Creates a clone of this ``Program``."""
...
Expand Down
3 changes: 3 additions & 0 deletions quil-py/quil/waveforms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Templates for generating discrete IQ value sequences representing Quil's defined set of waveforms."""

from quil.waveforms import *
Loading

0 comments on commit 3306782

Please sign in to comment.