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

Add tox and githooks #1

Merged
merged 2 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[run]
parallel = True
branch = True
source =
aqx

[paths]
source =
src/aqx
.tox/*/lib/python*/site-packages/aqx

[report]
show_missing = True

[html]
directory = build/coverage

[xml]
output = build/coverage/coverage.xml
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: local
hooks:
- id: tox
name: tox
stages: [push]
language: system
entry: tox
types: [python]
pass_filenames: false
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
**DO NOT SHARE OR TALK ABOUT THE CONTENTS OF THIS LIBRARY per the Amazon Beta NDA you signed.**

**aqx-python-ir** is a library that contains all the intermediate representations (IR) for AQx quantum tasks and offers serialization and deserialization of those IR payloads. Think of the IR as the contract between the AQx SDK and AQx API for quantum programs.
Amazon Qx Python IR is an open source library that contains all the intermediate representations (IR) for AQx quantum tasks and offers serialization and deserialization of those IR payloads. Think of the IR as the contract between the AQx SDK and AQx API for quantum programs.

## Installation

### Prerequisites
- Python 3.7+
### Steps
```bash
git clone https://github.com/aws/aqx-python-ir.git
pip install -e aqx-python-ir
```

To install test dependencies for running tests locally run:
```bash
pip install -e "aqx-python-ir[test]"
```

## Usage
There is currently only one kind of IR and that is the JsonAwsQuantumCircuitDescription, jaqcd. See below for it's usage.
Expand Down Expand Up @@ -57,6 +72,34 @@ instructions=[H(target=0, type=<Type.h: 'h'>), CNot(control=0, target=1, type=<T
"""
```

## Documentation
TODO

## Testing

Make sure to install test dependencies first:
```bash
pip install -e "aqx-python-ir[test]"
```

To run the unit tests:
```bash
tox
```

To run an individual test:
```bash
tox -- -k 'your_test'
```

## Building Sphinx docs
`cd` into the `doc` directory and run:
```bash
make html
```

You can edit the templates for any of the pages in the docs by editing the .rst files in the `doc` directory and then running `make html` again.

## License

This project is licensed under the Apache-2.0 License.
20 changes: 20 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = python -msphinx
SPHINXPROJ = aqx-ir
SOURCEDIR = .
BUILDDIR = ../build/documentation

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
56 changes: 11 additions & 45 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,30 @@
"""Sphinx configuration."""
from __future__ import print_function

import datetime
import os
import shutil


def run_apidoc(app):
"""Generate doc stubs using sphinx-apidoc."""
module_dir = os.path.join(app.srcdir, "../src/aqx")
output_dir = os.path.join(app.srcdir, "_apidoc")
excludes = []

# Ensure that any stale apidoc files are cleaned up first.
if os.path.exists(output_dir):
shutil.rmtree(output_dir)

cmd = [
"--separate",
"--module-first",
"--doc-project=API Reference",
"--implicit-namespaces",
"-o",
output_dir,
module_dir,
]
cmd.extend(excludes)

try:
from sphinx.ext import apidoc # Sphinx >= 1.7

apidoc.main(cmd)
except ImportError:
from sphinx import apidoc # Sphinx < 1.7

cmd.insert(0, apidoc.__file__)
apidoc.main(cmd)


def setup(app):
"""Register our sphinx-apidoc hook."""
app.connect("builder-inited", run_apidoc)

import pkg_resources

# Sphinx configuration below.
project = "aqx-ir"
version = "0.1.0"
version = pkg_resources.require(project)[0].version
release = version
copyright = "{}, Amazon.com".format(datetime.datetime.now().year)

extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode", "sphinx.ext.napoleon", "sphinx.ext.todo"]
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx.ext.coverage",
]

source_suffix = ".rst"
master_doc = "index"

autoclass_content = "class"
autoclass_content = "both"
autodoc_member_order = "bysource"
default_role = "py:obj"

html_theme = "haiku"
html_theme = "sphinx_rtd_theme"
htmlhelp_basename = "{}doc".format(project)

napoleon_use_rtype = False
7 changes: 4 additions & 3 deletions doc/index.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
AQxIR
=====
Amazon Qx Python IR
====================

Please replace this text with a short description of your package.
Amazon Qx Python IR is an open source library that contains all the intermediate representations (IR) for AQx quantum tasks and offers serialization and deserialization of those IR payloads. Think of the IR as the contract between the AQx SDK and AQx API for quantum programs.

Here you'll find an overview and API documentation for Amazon Qx Python IR. The project homepage is in GitHub, https://github.com/aws/aqx-python-ir, where you can find the source and installation instructions for the library.

Indices and tables
__________________
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.black]
line-length = 100
16 changes: 9 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ testpaths = test
line_length = 100
multi_line_output = 3
include_trailing_comma = true

formatters = black,isort
black_opts =
--line-length=100
autopep8_opts =
--max-line-length=100


[flake8]
ignore =
E203, # not pep8, black adds whitespace before ':'
W503, # not pep8, black adds line break before binary operator
max_line_length = 100
max-complexity = 10
exclude =
__pycache__
.tox
.git
bin
build
venv
10 changes: 6 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,25 @@

setup(
name="aqx-ir",
version="0.1.0",
version="0.1.1",
license="Apache License 2.0",
python_requires=">= 3.7",
packages=find_namespace_packages(where="src", exclude=("test",)),
package_dir={"": "src"},
install_requires=[
"pydantic"
],
install_requires=["pydantic"],
extras_require={
"test": [
"black",
"flake8",
"isort",
"pre-commit",
"pylint",
"pytest",
"pytest-cov",
"pytest-rerunfailures",
"pytest-xdist",
"sphinx",
"sphinx-rtd-theme",
"tox",
]
},
Expand Down
17 changes: 8 additions & 9 deletions src/aqx/ir/jaqcd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

from aqx.ir.jaqcd.instructions import (
from aqx.ir.jaqcd.instructions import ( # noqa: F401
CY,
CZ,
XX,
YY,
ZZ,
CCNot,
CNot,
CPhaseShift,
CPhaseShift00,
CPhaseShift01,
CPhaseShift10,
CSwap,
CY,
CZ,
H,
I,
ISwap,
Expand All @@ -30,18 +33,14 @@
Ry,
Rz,
S,
Swap,
Si,
Swap,
T,
Ti,
V,
Vi,
X,
XX,
Y,
YY,
Z,
ZZ
)
from aqx.ir.jaqcd.program import Program

from aqx.ir.jaqcd.program import Program # noqa: F401
8 changes: 4 additions & 4 deletions src/aqx/ir/jaqcd/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class Type(str, Enum):

class PhaseShift(SingleTarget, Angle):
"""
Phase shift gate. Shifts the phase between |0> and |1> by a given angle.
Phase shift gate. Shifts the phase between \\|0> and \\|1> by a given angle.

Attributes:
type (str): The instruction type. default = "phaseshift". (type) is optional.
Expand Down Expand Up @@ -404,7 +404,7 @@ class Type(str, Enum):

class CPhaseShift00(SingleTarget, SingleControl, Angle):
"""
Controlled phase shift gate that phases the |00> state.
Controlled phase shift gate that phases the \\|00> state.

Attributes:
type (str): The instruction type. default = "cphaseshift00". (type) is optional.
Expand All @@ -426,7 +426,7 @@ class Type(str, Enum):

class CPhaseShift01(SingleTarget, SingleControl, Angle):
"""
Controlled phase shift gate that phases the |01> state.
Controlled phase shift gate that phases the \\|01> state.

Attributes:
type (str): The instruction type. default = "cphaseshift01". (type) is optional.
Expand All @@ -448,7 +448,7 @@ class Type(str, Enum):

class CPhaseShift10(SingleTarget, SingleControl, Angle):
"""
Controlled phase shift gate that phases the |10> state.
Controlled phase shift gate that phases the \\|10> state.

Attributes:
type (str): The instruction type. default = "cphaseshift10". (type) is optional.
Expand Down
Loading