Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc(quil-py): Publish documentation on GitHub Pages #314

Merged
merged 39 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c957625
doc: Use pdoc to publish type hints
MarquessV Nov 21, 2023
735be10
add workflow to publish documentation on release builds
MarquessV Nov 22, 2023
f5859d0
bump rigetti-pyo3
MarquessV Nov 22, 2023
d782e69
re-structure identifier.py
MarquessV Nov 22, 2023
9f368f5
fix import
MarquessV Nov 22, 2023
3aacac7
move documentation workflow so it can be tested
MarquessV Nov 22, 2023
d7af2ca
commit the new workflow
MarquessV Nov 22, 2023
d7d16d5
revert test changes to validation module
MarquessV Nov 22, 2023
efafd04
commit Cargo.lock
MarquessV Nov 22, 2023
0ad2b4a
remove guardrails on test workflow
MarquessV Nov 22, 2023
67e52f4
add missing key
MarquessV Nov 22, 2023
03b2000
install cargo make
MarquessV Nov 22, 2023
f2b3468
write the file
MarquessV Nov 22, 2023
8d684bd
fix cwd
MarquessV Nov 22, 2023
b9e24e4
is this the right output dir?
MarquessV Nov 22, 2023
82d9324
fix task name
MarquessV Nov 22, 2023
87c8fd7
try adding github token
MarquessV Nov 22, 2023
7d9e7bf
why did that disable the workflow
MarquessV Nov 22, 2023
1625f9d
set permissions
MarquessV Nov 22, 2023
b8391e7
update README-py
MarquessV Nov 22, 2023
8a14741
improve module level documentation, update expression documentation
MarquessV Nov 22, 2023
d743e7e
use rigetti logo in docs
MarquessV Nov 22, 2023
b7d56c3
add quil-py documentation artifacts to gitignore
MarquessV Nov 22, 2023
ee3729c
try preview action
MarquessV Dec 1, 2023
d9e9ddf
configure preview action
MarquessV Dec 1, 2023
6daa3e4
key spec
MarquessV Dec 1, 2023
c19d369
restructure
MarquessV Dec 1, 2023
9bc4f1d
this?
MarquessV Dec 1, 2023
9b837d2
typo
MarquessV Dec 1, 2023
85c367f
set-preview-branch-to-main
MarquessV Dec 1, 2023
5b1230a
try this
MarquessV Dec 1, 2023
35f79bd
fix dependency tree
MarquessV Dec 1, 2023
8151a25
publish on push to main
MarquessV Dec 1, 2023
90e1c5e
test deploy
MarquessV Dec 1, 2023
3d3fe7a
deja vu
MarquessV Dec 1, 2023
068bb31
publish docs on push to main only
MarquessV Dec 1, 2023
c956ef8
update readme
MarquessV Dec 1, 2023
35d5357
remove build directory
MarquessV Dec 12, 2023
1a7d0c4
delete artifacts
MarquessV Dec 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Publish quil-py documentation

on:
push:
branches:
- main
pull_request:
types:
- opened
- reopened
- synchronize
- closed

jobs:
publish-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- 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
- name: Build quil-py documentation
uses: actions-rs/cargo@v1
with:
command: make
args: --cwd quil-py --makefile Makefile.toml docs
- name: Deploy preview
if: ${{ github.event_name == 'pull_request' }}
uses: rossjrw/pr-preview-action@v1
with:
source-dir: quil-py/build/docs
preview-branch: quil-py-docs
- name: Deploy docs
if: ${{ github.event_name == 'push' }}
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: quil-py/build/docs
publish_branch: quil-py-docs
2 changes: 1 addition & 1 deletion .github/workflows/publish-quil-py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ jobs:
publish-rust-crate:
name: Release
runs-on: ubuntu-latest
needs: [ publish-python-package ]
needs: publish-python-package
steps:
- uses: actions/checkout@v3
with:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ node_modules
# Python artifacts
*.so
__pycache__
**./.null-ls-cache*

# quil-py documentation
quil-py/build

4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion quil-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ strum.workspace = true
# pyo3 dependencies should be updated together
numpy = "0.20.0"
pyo3 = "0.20.0"
rigetti-pyo3 = "0.3"
rigetti-pyo3 = "0.3.1"

[build-dependencies]
pyo3-build-config = "0.20.0"
5 changes: 5 additions & 0 deletions quil-py/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ dependencies = [
"pytest",
]

[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.dev-flow]
dependencies = ["dev-test-flow", "pytest-flow", "stubtest"]

Expand Down
4 changes: 4 additions & 0 deletions quil-py/README-py.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
The `quil` package provides tools for constructing, manipulating, parsing, and printing [Quil](https://github.com/quil-lang/quil) programs. Internally, it is powered by [quil-rs](https://github.com/rigetti/quil-rs).

This package is still in early development and breaking changes should be expected between minor versions.

# Documentation

Documentation for the current release of `quil` is published [here](https://rigetti.github.io/quil-rs/quil.html). Every version of `quil` ships [with type stubs](https://github.com/rigetti/quil-rs/tree/main/quil-py/quil) that provide type hints and documentation to Python tooling and editors that support the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) or similar.
15 changes: 15 additions & 0 deletions quil-py/make_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pathlib import Path
import sys

import pdoc

import quil # noqa - we need to import quil for it to appear in sys.modules


if __name__ == "__main__":
print(dir(sys.modules["quil"]))
print(dir(sys.modules["quil.validation"]))
print([k for k in sys.modules.keys() if "quil" in k])
del sys.modules["quil.validation"]

pdoc.pdoc("quil", "!quil.quil", output_directory=Path("docs"))
7 changes: 7 additions & 0 deletions quil-py/out/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=./quil.html"/>
</head>
</html>
237 changes: 237 additions & 0 deletions quil-py/out/quil.html

Large diffs are not rendered by default.

233 changes: 233 additions & 0 deletions quil-py/out/quil/quil.html

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions quil-py/out/search.js

Large diffs are not rendered by default.

188 changes: 186 additions & 2 deletions quil-py/poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions quil-py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ black = "^23.1.0"
maturin = "^1.2.3"
mypy = "^1.1.1"
pytest = "^7.2.2"
pdoc = "^14.1.0"

[tool.maturin]
features = ["pyo3/extension-module"]
Expand Down
237 changes: 237 additions & 0 deletions quil-py/quil.html

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions quil-py/quil/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
"""
The `quil` package provides tools for constructing, manipulating, parsing, and printing [Quil](https://github.com/quil-lang/quil) programs.

⚠️ This package is still in early development and breaking changes should be expected between minor versions.
"""
from .quil import *
1 change: 1 addition & 0 deletions quil-py/quil/expression/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from quil.expression import *
55 changes: 38 additions & 17 deletions quil-py/quil/expression/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
The ``expression`` module contains classes for representing Quil expressions.
"""
from enum import Enum
from typing import Dict, final, Sequence, Optional, Union

Expand All @@ -14,30 +17,30 @@ class Expression:
"""
A Quil expression.

Variants:
``address``: An address defined by a ``MemoryReference``.
``function_call``: A ``FunctionCall``.
``infix``: An ``InfixExpression``.
``number``: A number defined as a ``complex``.
``pi``: The constant `pi`. No inner data.
``prefix``: A ``PrefixExpression``.
``variable``: A variable defined as a ``str``.
# Variants:
- ``address``: An address defined by a `quil.instructions.MemoryReference`.
- ``function_call``: A `FunctionCallExpression`.
- ``infix``: An `InfixExpression`.
- ``number``: A number defined as a `complex`.
- ``pi``: The constant ``pi``. No inner data.
- ``prefix``: A `PrefixExpression`.
- ``variable``: A variable defined as a `str`.

As seen above, some variants contain inner data that fully specify the expression.
For example, the ``number`` variant contains an ``int``. This is in contrast to variants like
``pi`` that have no inner data because they require none to fully specify the expression.
This difference is important for determining which methods are available for each variant.

Methods (for each variant):
``is_*``: Returns ``True`` if the expression is that variant, ``False`` otherwise.
Methods (for every variant):
- ``is_*``: Returns ``True`` if the expression is that variant, ``False`` otherwise.

If the variant has inner data:
``as_*``: returns the inner data if it is the given variant, ``None`` otherwise.
``to_*``: returns the inner data if it is the given variant, raises ``ValueError`` otherwise.
``from_*``: Creates a new ``Expression`` of the given variant from an instance of the inner type.
If the variant has inner data:
- ``as_*``: returns the inner data if it is the given variant, ``None`` otherwise.
- ``to_*``: returns the inner data if it is the given variant, raises ``ValueError`` otherwise.
- ``from_*``: Creates a new ``Expression`` of the given variant from an instance of the inner type.

If the variant doesn't have inner data (e.g. ``pi``)
``new_*``: Creates a new ``Expression`` for the variant
If the variant doesn't have inner data (e.g. ``pi``)
- ``new_*``: Creates a new ``Expression`` for the variant
"""

def inner(
Expand Down Expand Up @@ -113,7 +116,7 @@ class Expression:
...
def to_real(self) -> float:
"""
If this is a number with imaginary part "equal to" zero (of _small_ absolute value), return
If this is a number with imaginary part "equal to" zero (of <em>small</em> absolute value), return
that number. Otherwise, raises an ``EvaluationError``
"""
def __add__(self, other: "Expression") -> "Expression": ...
Expand All @@ -134,6 +137,9 @@ class Expression:
"""

class FunctionCallExpression:
"""
A Quil function call.
"""
@staticmethod
def __new__(cls, function: ExpressionFunction, expression: Expression) -> "FunctionCallExpression": ...
@property
Expand All @@ -146,6 +152,9 @@ class FunctionCallExpression:
def expression(self, expression: Expression): ...

class InfixExpression:
"""
A Quil infix expression.
"""
@staticmethod
def __new__(cls, left: Expression, operator: InfixOperator, right: Expression): ...
@property
Expand All @@ -162,6 +171,9 @@ class InfixExpression:
def right(self, expression: Expression): ...

class PrefixExpression:
"""
A Quil prefix expression.
"""
@staticmethod
def __new__(cls, operator: PrefixOperator, expression: Expression): ...
@property
Expand All @@ -175,6 +187,9 @@ class PrefixExpression:

@final
class ExpressionFunction(Enum):
"""
An enum representing a Quil function that can be applied to an expression.
"""
Cis = "CIS"
Cosine = "COSINE"
Exponent = "EXPONENT"
Expand All @@ -183,11 +198,17 @@ class ExpressionFunction(Enum):

@final
class PrefixOperator(Enum):
"""
An enum that represents the operators supported on a prefix expression.
"""
Plus = "PLUS"
Minus = "MINUS"

@final
class InfixOperator(Enum):
"""
An enum that represents the operators supported on an infix expression.
"""
Caret = "CARET"
Plus = "PLUS"
Minus = "MINUS"
Expand Down
4 changes: 4 additions & 0 deletions quil-py/quil/instructions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
The `quil.instructions` module contains classes for representing Quil instructions.
"""
from quil.instructions import *
Loading
Loading