From 84c64fc18d34953e933cf5d6f757696ba3368040 Mon Sep 17 00:00:00 2001 From: gecrooks Date: Fri, 11 Dec 2020 18:07:59 -0800 Subject: [PATCH 01/11] Port diamond norm from quantumflow to own package --- Makefile | 12 +- README.md | 704 +----------------- docs/conf.py | 2 +- .../__init__.py | 1 + .../about.py | 6 +- .../config.py | 11 +- .../config_test.py | 12 +- qf_diamond_norm/info.py | 83 +++ qf_diamond_norm/info_test.py | 76 ++ setup.cfg | 17 +- 10 files changed, 218 insertions(+), 706 deletions(-) rename {gecrooks_python_template => qf_diamond_norm}/__init__.py (86%) rename {gecrooks_python_template => qf_diamond_norm}/about.py (77%) rename {gecrooks_python_template => qf_diamond_norm}/config.py (81%) rename {gecrooks_python_template => qf_diamond_norm}/config_test.py (70%) create mode 100644 qf_diamond_norm/info.py create mode 100644 qf_diamond_norm/info_test.py diff --git a/Makefile b/Makefile index 5b56d5a..1664a16 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ .DEFAULT_GOAL := help -PROJECT = gecrooks_python_template +PROJECT = qf_diamond_norm FILES = $(PROJECT) docs/conf.py setup.py help: @@ -21,13 +21,9 @@ coverage: ## Report test coverage @echo lint: ## Lint check python source - @echo - isort --check -m 3 --tc $(PROJECT) || echo "FAILED isort!" - @echo - black --diff --color $(PROJECT) || echo "FAILED black" - @echo - flake8 $(FILES) || echo "FAILED flake8" - @echo + @isort --check -m 3 --tc $(PROJECT) || echo "isort: FAILED!" + @black --check --quiet $(PROJECT) || echo "black: FAILED!" + @flake8 --quiet --quiet --output-file=/dev/null $(FILES) || echo "flake8: FAILED!" delint: ## Run isort and black to delint project @echo diff --git a/README.md b/README.md index d674321..7d1c1d0 100644 --- a/README.md +++ b/README.md @@ -1,694 +1,44 @@ -# gecrooks-python-template: Minimal viable setup for an open source, github hosted, python package +# QuantumFlow Diamond Norm +Gavin E. Crooks (2020) -![Build Status](https://github.com/gecrooks/gecrooks-python-template/workflows/Build/badge.svg) [![Documentation Status](https://readthedocs.org/projects/gecrooks-python-template/badge/?version=latest)](https://gecrooks-python-template.readthedocs.io/en/latest/?badge=latest) - -[Source](https://github.com/gecrooks/gecrooks-python-template) - - -## Installation for development - -``` -$ git clone https://github.com/gecrooks/gecrooks-python-template.git -$ cd gecrooks-python-template -$ pip install -e .[dev] -``` - - -## About: On the creation and crafting of a python project - -This is a discussion of the steps needed to setup an open source, github hosted, python package ready for further development. - -## Naming - -The first decision to make is the name of the project. And for python packages the most important criteria is that the name isn't already taken on [pypi](https://pypi.org/), the repository from which we install python packages with `pip`. So we should do a quick Internet search: This name is available on pypi, there are no other repos of that name on github, and a google search doesn't pull up anything relevant. So we're good to go. - -Note that github repo and pypi packages are named using dashes (`-`), but that the corresponsing python module are named with underscores (`_`). (The reason for this dichotomy appears to be that underscores don't work well in URLs, but dashes are frowned upon in filenames.) - -## License - -The next decision is which of the plethora of [Open Source](https://opensource.org/licenses) licenses to use. We'll use the [Apache License](https://opensource.org/licenses/Apache-2.0), a perfectly reasonable, and increasingly popular choice. - - -## Create repo - -Next we need to initialize a git repo. It's easiest to create the repo on github and clone to our local machine (This way we don't have to mess around setting the origin and such like). Github will helpfully add a `README.md`, the license, and a python `.gitignore` for us. On Github, add a description, website url (typically pointing at readthedocs), project tags, and review the rest of github's settings. - - -Note that MacOS likes to scatter `.DS_Store` folders around (they store the finder icon display options). We don't want to accidentally add these to our repo. But this is a machine/developer issue, not a project issue. So if you're on a mac you should configure git to ignore `.DS_Store` globally. - -``` - # specify a global exclusion list - git config --global core.excludesfile ~/.gitignore - # adding .DS_Store to that list - echo .DS_Store >> ~/.gitignore -``` - -## Clone repo - -On our local machine the first thing we do is create a new conda environment. (You have conda installed, right?) This way if we balls up the installation of some dependency (which happens distressingly often) we can nuke the environment and start again. -``` - $ conda create --name GPT - $ source activate GPT - (GPT) $ python --version - Python 3.8.3 -``` - -Now we clone the repo locally. - -``` - (GPT) $ git clone https://github.com/gecrooks/gecrooks-python-template.git - Cloning into 'gecrooks-python-template'... - remote: Enumerating objects: 4, done. - remote: Counting objects: 100% (4/4), done. - remote: Compressing objects: 100% (3/3), done. - remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0 - Unpacking objects: 100% (4/4), done. - (GPT) $ cd gecrooks-python-template -``` - -Lets tag this initial commit for posterities sake (And so I can [link](https://github.com/gecrooks/gecrooks-python-template/releases/tag/v0.0.0) to the code at this instance). -``` - (GPT) $ git tag v0.0.0 - (GPT) $ git push origin v0.0.0 -``` -For reasons that are unclear to me the regular `git push` doesn't push tags. We have push the tags explicitly by name. Note we need to specify a full MAJOR.MINOR.PATCH version number, and not just e.g. '0.1', for technical reasons that have to do with how we're going to manage package versions. - - -## Branch -It's always best to craft code in a branch, and then merge that code into the master branch. -``` -$ git branch gec001-init -$ git checkout gec001-init -Switched to branch 'gec001-init' -``` -I tend to name branches with my initials (so I know it's my branch on multi-developer projects), a serial number (so I can keep track of the chronological order of branches), and a keyword (if I know ahead of time what the branch is for). - - -## Packaging - -Let's complete the minimum viable python project. We need the actual python module, signaled by a (currently) blank `__init__.py` file. -``` - (GPT) $ mkdir gecrooks_python_template - (GPT) $ touch gecrooks_python_template/__init__.py -``` - -Python standards for packaging and distribution seems to be in flux (again...). So following what I think the current standard is we need 3 files, `setup.py`, `pyproject.toml`, and `setup.cfg`. - -The modern `setup.py` is just a husk: - -``` -#!/usr/bin/env python - -import setuptools - -if __name__ == "__main__": - setuptools.setup(use_scm_version=True) -``` -Our only addition is `use_scm_version=True`, which activates versioning with git tags. More on that anon. Don't forget to set executable permissions on the setup.py script. -``` - $ chmod a+x setup.py -``` -The [pyproject.toml](https://snarky.ca/what-the-heck-is-pyproject-toml/) file (written in [toml](https://github.com/toml-lang/toml) format) is a recent addition to the canon. It specifies the tools used to build the project. -``` -# pyproject.toml -[build-system] -requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"] -build-backend = "setuptools.build_meta" - - -# pyproject.toml -[tool.setuptools_scm] - -``` -Again, the parts with `setuptools_scm` are additions. - - -All of the rest of the metadata goes in `setup.cfg` (in INI format). -``` -# Setup Configuration File -# https://docs.python.org/3/distutils/configfile.html -# [INI](https://docs.python.org/3/install/index.html#inst-config-syntax) file format. - -[metadata] -name = gecrooks-python-template -url = https://github.com/gecrooks/gecrooks_python_template/ -author = Gavin Crooks -author_email = gavincrooks@gmail.com -description = "Minimal Viable Product for an open source, github hosted, python package" -long_description = file:README.md -long_description_content_type = text/markdown -license_file = LICENSE -license = Apache-2.0 - -classifiers= - Development Status :: 4 - Beta - Intended Audience :: Science/Research - License :: OSI Approved :: Apache Software License - Topic :: Scientific/Engineering - Programming Language :: Python - Natural Language :: English - Topic :: Software Development :: Libraries - Topic :: Software Development :: Libraries :: Python Modules - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Operating System :: OS Independent - - -[options] -zip_safe = True -python_requires = >= 3.7 - -# importlib_metadata required for python 3.7 -install_requires = - importlib_metadata - numpy - -setup_requires = - setuptools_scm - -[options.extras_require] -dev = - pytest - pytest-cov - flake8 - mypy - sphinx - sphinxcontrib-bibtex - setuptools_scm -``` - -It's good practice to support at least two consecutive versions of python. Starting with 3.9, python is moving to an annual [release schedule](https://www.python.org/dev/peps/pep-0602/). The initial 3.x.0 release will be in early October and the first bug patch 3.x.1 in early December, second in February, and so on. Since it takes many important packages some time to upgrade (e.g. numpy and tensorflow are often bottlenecks), one should probably plan to upgrade python support around February each year. Upgrading involves changing the python version numbers in the tests and `config.cfg`, and then cleaning up any `__future__` or conditional imports, or other hacks added to maintain compatibility with older python releases. - - -We can now install our package (as editable -e, so that the code in our repo is live). -``` - $ pip install -e .[dev] -``` -The optional `[dev]` will install all of the extra packages we need for test and development, listed under `[options.extras_require]` above. - - - -## Versioning -Our project needs a version number (e.g. '3.1.4'). We'll try and follow the [semantic versioning](https://semver.org/) conventions. But as long as the major version number is '0' we're allowed to break things. - -There should be a -[single source of truth](https://packaging.python.org/guides/single-sourcing-package-version/) for this number. -My favored approach is use git tags as the source of truth (Option 7 in the above linked list). We're going to tag releases anyways, so if we also hard code the version number into the python code we'd violate the single source of truth principle. We use the [setuptools_scm](https://github.com/pypa/setuptools_scm) package to automatically construct a version number from the latest git tag during installation. - -The convention is that the version number of a python packages should be available as `packagename.__version__`. -So we add the following code to `gecrooks_python_template/config.py` to extract the version number metadata. -``` -try: - # python >= 3.8 - from importlib import metadata as importlib_metadata # type: ignore -except ImportError: # pragma: no cover - # python == 3.7 - import importlib_metadata # type: ignore # noqa: F401 - - -__all__ = ["__version__", "about"] - - -package_name = "gecrooks_python_template" - -try: - __version__ = importlib_metadata.version(package_name) # type: ignore -except Exception: # pragma: no cover - # package is not installed - __version__ = "?.?.?" - - -``` -and then in `gecrooks_python_template/__init__.py`, we import this version number. -``` -from .config import __version__ as __version__ # noqa: F401 -``` -We put the code to extract the version number in `config.py` and not `__init__.py`, because we don't want to pollute our top level package namespace. - -The various pragmas in the code above ("pragma: no cover" and "type: ignore") are there because the conditional import needed for python 3.7 compatibility confuses both our type checker and code coverage tools. - -## about - -One of my tricks is to add a function to print the versions of the core upstream dependencies. This can be extremely helpful when debugging configuration or system dependent bugs, particularly when running continuous integration tests. - -``` -# Configuration (> python -m gecrooks_python_template.about) -platform macOS-10.13.6-x86_64-i386-64bit -gecrooks-python-template 0.0.1 -python 3.8.3 -numpy 1.18.5 -pytest 5.4.3 -pytest-cov 2.10.0 -flake8 3.8.3 -mypy 0.780 -sphinx 3.1.1 -sphinxcontrib-bibtex 1.0.0 -setuptools_scm 4.1.2 -``` -The `about()` function to print this information is placed in `config.py`. The file `about.py` contains the standard python command line interface (CLI), -``` -if __name__ == '__main__': - import gecrooks_python_template - gecrooks_python_template.about() -``` -It's important that `about.py` isn't imported by any other code in the package, else we'll get multiple import warnings when we try to run the CLI. - - -## Unit tests - -Way back when I worked as a commercial programmer, the two most important things that I learned were source control and unit tests. Both were largely unknown in the academic world at the time. - -(I was once talking to a chap who was developing a new experimental platform. The plan was to build several dozens of these gadgets, and sell them to other research groups so they didn't have to build their own. A couple of grad students wandered in. They were working with one of the prototypes, and they'd found some minor bug. Oh yes, says the chap, who goes over to his computer, pulls up the relevant file, edits the code, and gives the students a new version of that file. He didn't run any tests, because there were no tests. And there was no source control, so there was no record of the change he'd just made. That was it. The horror.) - -Currently, the two main options for python unit tests appear to be `unittest` from the standard library and `pytest`. To me `unittest` feels very javonic. There's a lot of boiler plate code and I believe it's a direct descendant of an early java unit testing framework. Pytest, on the other hand, feels pythonic. In the basic case all we have to do is to write functions (whose names are prefixed with 'test_'), within which we test code with `asserts`. Easy. - -There's two common ways to organize tests. Either we place tests in a separate directory, or they live in the main package along with the rest of the code. In the past I've used the former approach. It keeps the test organized and separate from the production code. But I'm going to try the second approach for this project. The advantage is that the unit tests for a piece of code live right next to the code being tested. - -Let's test that we can access the version number (There is no piece of code too trivial that it shouldn't have a unit test.) In `gecrooks_python_template/config_test.py` we add - -``` -import gecrooks_python_template - -def test_version(): - assert gecrooks_python_template.__version__ -``` -and run our test. (The 'python -m' prefix isn't strictly necessary, but it helps ensure that pytest is running under the correct copy of python.) -``` - -(GTP) $ python -m pytest -========================================================================================== test session starts =========================================================================================== -platform darwin -- Python 3.8.3, pytest-5.4.3, py-1.8.2, pluggy-0.13.1 -rootdir: /Users/work/Work/Projects/gecrooks_python_template -collected 1 item - -gecrooks_python_template/config_test.py . [100%] - -=========================================================================================== 1 passed in 0.02s ============================================================================================ -``` - -Note that in the main code we'll access the package with relative imports, e.g. -``` -from . import __version__ -``` -But in the test code we use absolute imports. -``` -from gecrooks_python_template import __version__ -``` -In tests we want to access our code in the same way we would access it from the outside as an end user. - - -## Test coverage - -At a bare minimum the unit tests should run (almost) every line of code. If a line of code never runs, then how do you know it works at all? - -So we want to monitor the test coverage. The [pytest-cov](https://pypi.org/project/pytest-cov/) plugin to pytest will do this for us. Configuration is placed in the setup.cfg file (Config can also be placed in a seperate `.coveragerc`, but I think its better to avoid a proliferation of configuration files.) -``` -# pytest configuration -[tool:pytest] -testpaths = - gecrooks_python_template - - -# Configuration for test coverage -# -# https://coverage.readthedocs.io/en/latest/config.html -# -# python -m pytest --cov - -[coverage:paths] -source = - gecrooks_python_template - -[coverage:run] -omit = - *_test.py - -[coverage:report] -# Use ``# pragma: no cover`` to exclude specific lines -exclude_lines = - pragma: no cover -``` - -We have to explicitly omit the unit tests since we have placed the test files in the same directories as the code to test. - -The pragam `pragma: no cover` is used to mark untestable lines. This often happens with conditional imports used for backwards compatibility between python versions. - - -## Linting - -We need to lint our code before pushing any commits. I like [flake8](https://flake8.pycqa.org/en/latest/). It's faster than pylint, and I think better error messages. I will hereby declare: - - The depth of the indentation shall be 4 spaces. - And 4 spaces shall be the depth of the indentation. - Two spaces thou shall not use. - And tabs are right out. - -Four spaces is standard. [Tabs are evil](https://www.emacswiki.org/emacs/TabsAreEvil). I've worked on a project with 2-space indents, and I see the appeal, but I found it really weird. - -Most of flake8's defaults are perfectly reasonable and in line with [PEP8](https://www.python.org/dev/peps/pep-0008/) guidance. But even [Linus](https://lkml.org/lkml/2020/5/29/1038) agrees that the old standard of 80 columns of text is too restrictive. (Allegedly, 2-space indents was [Google's](https://www.youtube.com/watch?v=wf-BqAjZb8M&feature=youtu.be&t=260) solution to the problem that 80 character lines are too short. Just make the indents smaller!) Raymond Hettinger suggests 90ish (without a hard cutoff), and [black](https://black.readthedocs.io/en/stable/the_black_code_style.html) uses 88. So let's try 88. - - -The configuration also lives in `setup.cfg`. -``` -# flake8 linter configuration -[flake8] -max-line-length = 88 -ignore = E203, W503 -``` -We need to override the linter on occasion. We add pragma such as `# noqa: F401` to assert that no, really, in this case we do know what we're doing. - - -Two other python code format tools to consider using are [isort](https://pypi.org/project/isort/) and [black, The uncompromising code formatter](https://black.readthedocs.io/en/stable/). Isort sorts your import statements into a canonical order. And Black is the Model-T Ford of code formatting -- any format you want, so long as it's Black. I could quibble about some of Black's code style, but in the end it's just easier to blacken your code and accept black's choices, and thereby gain a consistent coding style across developers. - -The command `make delint` will run these `isort` and `black` on your code, with the right magic incantations so that they are compatible. - - -## Copyright -It's common practice to add a copyright and license notice to the top of every source file -- something like this: -``` - -# Copyright 2019-, Gavin E. Crooks and contributors -# -# This source code is licensed under the Apache License, Version 2.0 found in -# the LICENSE.txt file in the root directory of this source tree. - -``` - -I tend to forget to add these lines. So let's add a unit test `gecrooks_python_template/config_test.py::test_copyright` to make sure we don't. -``` -def test_copyright(): - """Check that source code files contain a copyright line""" - exclude = set(['gecrooks_python_template/version.py']) - for fname in glob.glob('gecrooks_python_template/**/*.py', recursive=True): - if fname in exclude: - continue - print("Checking " + fname + " for copyright header") - - with open(fname) as f: - for line in f.readlines(): - if not line.strip(): - continue - assert line.startswith('# Copyright') - break -``` - - -## API Documentation -[Sphinx](https://www.sphinx-doc.org/en/master/usage/quickstart.html) is the standard -tool used to generate API documentation from the python source. Use the handy quick start tools. -``` -$ mkdir docs -$ cd docs -$ sphinx-quickstart -``` -The defaults are reasonable. Enter the project name and author when prompted. - -Edit the conf.py, and add the following collection of extensions. -``` -extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.napoleon', -] -``` -[Autodoc](https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html) automatically extracts documentation from docstrings, and [napolean](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html) enables [Google style](http://google.github.io/styleguide/pyguide.html) python docstrings. - -We also add a newline at the end of `conf.py`, since the lack of a blank line at the end upsets our linter. - -Go ahead and give it a whirl. This won't do anything interesting yet, but it's a start. -``` -$ make html -``` - -One problem is that sphinx creates three (initially) empty directories, `_build`, `_static`, and `_templates`. But we can't add empty directories to git, since git only tracks files. The workaround is to add an empty `.gitignore` file to each of the `_static` and `_templates` directories. (Sphinx will create the `_build` directory when it needs it.) - -``` -$ touch _templates/.gitignore _build/.gitignore _static/.gitignore -$ git add -f _templates/.gitignore _build/.gitignore _static/.gitignore -$ git add Makefile *.* -# cd .. -``` - - - -## Makefile -I like to add a Makefile with targets for all of the common development tools I need to run. This is partially for convenience, and partially as documentation, i.e. here are all the commands you need to run to test, lint, typecheck, and build the code (and so on.) I use a [clever hack](https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html) so that the makefile self documents. - -``` -(GTP) $ make -all Run all tests -test Run unittests -coverage Report test coverage -lint Lint check python source -delint Run isort and black to delint project -typecheck Static typechecking -docs Build documentation -docs-open Build documentation and open in webbrowser -docs-clean Clean documentation build -pragmas Report all pragmas in code -about Report versions of dependent packages -status git status -uno -build Setuptools build -clean Clean up after setuptools -``` - -The pragmas target searches the code and lists all of the pragmas that occur. Common uses of [pragmas](https://en.wikipedia.org/wiki/Directive_(programming)) are to override the linter, tester, or typechecker. I also tend to scatter other keywords throughout my code: TODO (For things that need doing), FIXME (For code that's broken, but I can't fix right this moment), DOCME (code that needs more documentation), and TESTME (for code that needs more tests). In principle, production code shouldn't have these pragmas. Either the problem should be fixed, or if it can't be immediately fixed, it should become a github issue. - - -## Readthedocs -We'll host our API documentation on [Read the Docs](readthedocs.org). We'll need a basic configuration file, `.readthedocs.yml`. -``` -version: 2 -formats: [] -sphinx: - configuration: docs/conf.py -python: - version: 3.8 -``` -I've already got a readthedocs account, so setting up a new project takes but a few minutes. - - -## README.md - -We add some basic information and installation instructions to `README.mb`. Github displays this file on your project home page (but under the file list, so if you have a lot of files at the top level of your project, people might not notice your README.) - -A handy trick is to add Build Status and Documentation Status badges for Github actions tests and readthedocs. These will proudly declare that your tests are passing (hopefully). (See top of this file) - - -## Continuous Integration - -Another brilliant advance to software engineering practice is continuous integration (CI). The basic idea is that all code gets thoroughly tested before it's added to the master branch. - -Github now makes this very easy to setup with Github actions. They even provide basic templates. This testing workflow lives in `.github/workflows/python-build.yml`, and is a modification of Github's `python-package.yml` workflow. -``` -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Python package - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - schedule: - - cron: "0 13 * * *" # Every day at 1pm UTC (6am PST) - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ['3.7', '3.8'] - - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - python -m pip install -e .[dev] # install package + test dependencies - - name: About - run: | - python -m $(python -Wi setup.py --name).about - - name: Lint with flake8 - run: | - flake8 . - - name: Test with pytest - run: | - python -m pytest --cov-fail-under 100 - - name: Typecheck with mypy - run: | - mypy - - name: Build documentation with sphinx - run: | - sphinx-build -M html docs docs/_build - -``` -Note that these tests are picky. Not only must the unit tests pass, but test coverage must be 100%, the code must be delinted, blackened, isorted, and properly typed, and the docs have to build without error. - -It's a good idea to set a cron job to run the test suite against the main branch on a regular basis (the `schedule` block above). This will alert you of problems caused by your dependencies updating. (For instance, one of my other projects just broke, apparently because flake8 updated it's rules.) - -Let's add, commit, and push our changes. -``` -$ git status -On branch gec001-init -Changes to be committed: - (use "git reset HEAD ..." to unstage) - - new file: .readthedocs.yml - new file: .github/workflows/python-package.yml - new file: Makefile - modified: README.md - new file: docs/Makefile - new file: docs/_build/.gitignore - new file: docs/_static/.gitignore - new file: docs/_templates/.gitignore - new file: docs/conf.py - new file: docs/index.rst - new file: pyproject.toml - new file: gecrooks_python_template/__init__.py - new file: gecrooks_python_template/about.py - new file: gecrooks_python_template/config.py - new file: gecrooks_python_template/config_test.py - new file: setup.cfg - new file: setup.py - -$ git commit -m "Minimum viable package" -... -$ git push --set-upstream origin gec001-init -... -``` -If all goes well Github will see our push, and build and test the code in the branch. Probably all the tests won't pass on the first try. It's easy to forget something (which is why we have automatic tests). So tweak the code, and push another commit until the tests pass. - - - -## PyPi - -We should now be ready to do a test submission to PyPI, The Python Package Index (PyPI). -Follow the directions laid out in the [python packaging](https://packaging.python.org/tutorials/packaging-projects/) documentation. - -``` -$ pip install -q wheel setuptools twine -... -$ git tag v0.1.0rc1 -$ python setup.py sdist bdist_wheel -... -``` -We tag our release candidate so that we get a clean version number (pypi will object to the development version numbers setuptools_scm generates if the tag or git repo isn't up to date). - -First we push to the pypi's test repository. -``` -(GTP) $ python -m twine upload --repository testpypi dist/* -``` -You'll need to create a pypi account if you don't already have one. - -Let's make sure it worked by installing from pypi into a fresh conda environment. -``` -(GTP) $ conda deactivate -$ conda create --name tmp -$ conda activate tmp -(tmp) $ pip install --index-url https://test.pypi.org/simple/ --no-deps gecrooks-python-template -(tmp) $ python -m gecrooks_python_template.about -(tmp) $ conda activate GTP -``` - +![Build Status](https://github.com/gecrooks/qf-diamond-norm/workflows/Build/badge.svg) [![Documentation Status](https://readthedocs.org/projects/qf-diamond-norm/badge/?version=latest)](https://gecrooks-python-template.readthedocs.io/en/latest/?badge=latest) -## Merge and Tag +[Source](https://github.com/gecrooks/qf-diamond-norm) -Over on github we create a pull request, wait for the github action checks to give us the green light once all the tests have passed, and then squash and merge. +Calculation of the diamond norm between two completely positive trace-preserving (CPTP) superoperators, using +the [QuantumFlow](https://github.com/gecrooks/quantumflow) package -The full developer sequence goes something like this -1.) Sync the master branch. -``` -$ git checkout master -$ git pull origin master -``` -(If we're working on somebody else's project, this step is a little more complicated. We fork the project on github, clone our fork to the local machine, and then set git's 'upstream' to be the original repo. We then sync our local master branch with the upstream master branch -``` -$ git checkout master -$ git fetch upstream -$ git merge upstream/master -``` -This should go smoothly as long as you never commit directly to your local master branch.) +The calculation uses the simplified semidefinite program of Watrous +[arXiv:0901.4709](http://arxiv.org/abs/0901.4709) +[J. Watrous, [Theory of Computing 5, 11, pp. 217-238 +(2009)](http://theoryofcomputing.org/articles/v005a011/)] -2.) Create a working branch. -``` -$ git branch BRANCH -$ git checkout BRANCH -``` - -3.) Do a bunch of development on the branch, committing incremental changes as we go along. +Kudos: Based on MatLab code written by [Marcus P. da Silva](https://github.com/BBN-Q/matlab-diamond-norm/) -4.) Sync the master branch with github (since other development may be ongoing.) (i.e. repeat step 1) -5.) Rebase our branch to master. -``` -$ git checkout BRANCH -$ git rebase master -``` -If there are conflicts, resolve them, and then go back to step 4. +## Installation +Note: Diamond norm requires that the "cvxpy" package (and dependencies) be fully installed. Installing cvxpy via pip +does not correctly install all the necessary packages. -6.) Sync our branch to github ``` -$ git push +$ conda install -c conda-forge cvxpy +$ git clone https://github.com/gecrooks/qf_diamond_norm.git +$ cd qf_diamond_norm +$ pip install -e . ``` -7.) Over on github, create a pull request to merge into the master branch - -8.) Wait for the integration tests to pass. If they don't, fix them, and then go back to step 4. - -9.) Squash and merge into the master branch on github. Squashing merges all of our commits on the branch into a single commit to merge into the master branch. We generally don't want to pollute the master repo history with lots of micro commits. (On multi-developer projects, code should be reviewed. Somebody other than the branch author approves the changes before the final merge into master.) - -10.) Goto step 1. Back on our local machine, we resync master, create a new branch, and continue developing. - - -## Tag and release - -Assuming everything went well, you can now upload a release to pypi proper. We can add a [github workflow](.github/workflows/python-publish.yml) to automatically upload new releases tagged on github. The only additional configuration is to upload `PYPI_USERNAME` and `PYPI_PASSWORD` to github as secrets (under you repo settings). - - - -## Conclusion - -By my count we have 13 configuration files (In python, toml, yaml, INI, gitignore, Makefile, and plain text formats), 2 documentation files, one file of unit tests, and 3 files of code (containing 31 lines of code). We're now ready to create a new git branch and start coding in earnest. - - -## License - -This software template is public domain. The included open-source software license `LICENSE.txt` and copyright lines are for illustrative purposes only. If you wish to use this template as the basis of your own project, you should feel free to assert your own copyrights (at the top of the python source code files) and subsitute your own choice of software license. - -Gavin E. Crooks (2020) - - This is free and unencumbered software released into the public domain. - - Anyone is free to copy, modify, publish, use, compile, sell, or - distribute this software, either in source code form or as a compiled - binary, for any purpose, commercial or non-commercial, and by any - means. +## Example - In jurisdictions that recognize copyright laws, the author or authors - of this software dedicate any and all copyright interest in the - software to the public domain. We make this dedication for the benefit - of the public at large and to the detriment of our heirs and - successors. We intend this dedication to be an overt act of - relinquishment in perpetuity of all present and future rights to this - software under copyright law. +''' + > import quantumflow as qf + > from qf_diamond_norm import diamond_norm + > chan0 = qf.random_channel([0, 1, 2]) # 3-qubit channel + > chan1 = qf.random_channel([0, 1, 2]) + > dn = diamond_norm(chan0, chan1) + > print(dn) +''' - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR - OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - OTHER DEALINGS IN THE SOFTWARE. diff --git a/docs/conf.py b/docs/conf.py index f7542d4..5ea4998 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -17,7 +17,7 @@ # -- Project information ----------------------------------------------------- -project = "python_mvp" +project = "qf_diamond_norm" copyright = "2020, Gavin Crooks" author = "Gavin Crooks" diff --git a/gecrooks_python_template/__init__.py b/qf_diamond_norm/__init__.py similarity index 86% rename from gecrooks_python_template/__init__.py rename to qf_diamond_norm/__init__.py index de2adb4..ecdf2b1 100644 --- a/gecrooks_python_template/__init__.py +++ b/qf_diamond_norm/__init__.py @@ -5,3 +5,4 @@ from .config import __version__ # noqa: F401 from .config import about # noqa: F401 +from .info import diamond_norm # noqa: F401 diff --git a/gecrooks_python_template/about.py b/qf_diamond_norm/about.py similarity index 77% rename from gecrooks_python_template/about.py rename to qf_diamond_norm/about.py index 9ac4a9f..174b102 100644 --- a/gecrooks_python_template/about.py +++ b/qf_diamond_norm/about.py @@ -4,12 +4,12 @@ # the LICENSE.txt file in the root directory of this source tree. # Command line interface for the about() function -# > python -m gecrooks_python_template.about +# > python -m qf_diamond_norm.about # # NB: This module should not be imported by any other code in the package # (else we will get multiple import warnings) if __name__ == "__main__": - import gecrooks_python_template + import qf_diamond_norm - gecrooks_python_template.about() + qf_diamond_norm.about() diff --git a/gecrooks_python_template/config.py b/qf_diamond_norm/config.py similarity index 81% rename from gecrooks_python_template/config.py rename to qf_diamond_norm/config.py index f0624e9..079d977 100644 --- a/gecrooks_python_template/config.py +++ b/qf_diamond_norm/config.py @@ -23,7 +23,7 @@ __all__ = ["__version__", "about"] -package_name = "gecrooks_python_template" +package_name = "qf_diamond_norm" try: __version__ = importlib_metadata.version(package_name) # type: ignore @@ -33,13 +33,18 @@ def about(file: typing.TextIO = None) -> None: - f"""Print information about the configuration + f"""Print information about the package ``> python -m {package_name}.about`` Args: file: Output stream (Defaults to stdout) """ + metadata = importlib_metadata.metadata(package_name) # type: ignore + print(f"# {metadata['Name']}", file=file) + print(f"{metadata['Summary']}", file=file) + print(f"{metadata['Home-page']}", file=file) + name_width = 24 versions = {} versions["platform"] = platform.platform(aliased=True) @@ -54,7 +59,7 @@ def about(file: typing.TextIO = None) -> None: pass print(file=file) - print(f"# Configuration (> python -m {package_name}.about)", file=file) + print(f"# Configuration", file=file) for name, vers in versions.items(): print(name.ljust(name_width), vers, file=file) print(file=file) diff --git a/gecrooks_python_template/config_test.py b/qf_diamond_norm/config_test.py similarity index 70% rename from gecrooks_python_template/config_test.py rename to qf_diamond_norm/config_test.py index b460e59..5fa413c 100644 --- a/gecrooks_python_template/config_test.py +++ b/qf_diamond_norm/config_test.py @@ -7,28 +7,28 @@ import io import subprocess -import gecrooks_python_template +import qf_diamond_norm as pkg def test_version() -> None: - assert gecrooks_python_template.__version__ + assert pkg.__version__ def test_about() -> None: out = io.StringIO() - gecrooks_python_template.about(out) + pkg.about(out) print(out) def test_about_main() -> None: - rval = subprocess.call(["python", "-m", "gecrooks_python_template.about"]) + rval = subprocess.call(["python", "-m", f"{pkg.__name__}.about"]) assert rval == 0 def test_copyright() -> None: """Check that source code files contain a copyright line""" - exclude = set(["gecrooks_python_template/version.py"]) - for fname in glob.glob("gecrooks_python_template/**/*.py", recursive=True): + exclude = set([f"{pkg.__name__}/version.py"]) + for fname in glob.glob(f"{pkg.__name__}/**/*.py", recursive=True): if fname in exclude: continue print("Checking " + fname + " for copyright header") diff --git a/qf_diamond_norm/info.py b/qf_diamond_norm/info.py new file mode 100644 index 0000000..ceaf66e --- /dev/null +++ b/qf_diamond_norm/info.py @@ -0,0 +1,83 @@ +# Copyright 2020-, Gavin E. Crooks and contributors +# +# This source code is licensed under the Apache License, Version 2.0 found in +# the LICENSE.txt file in the root directory of this source tree. + + +""" +==================== +Information Measures +==================== + +Channel Measures +################# + +.. autofunction:: diamond_norm +""" + +import numpy as np +from quantumflow import Channel + +__all__ = ("diamond_norm",) + + +def diamond_norm(chan0: Channel, chan1: Channel) -> float: + """Return the diamond norm between two completely positive + trace-preserving (CPTP) superoperators. + + Note: Requires "cvxpy" package (and dependencies) to be fully installed. + + The calculation uses the simplified semidefinite program of Watrous + [arXiv:0901.4709](http://arxiv.org/abs/0901.4709) + [J. Watrous, [Theory of Computing 5, 11, pp. 217-238 + (2009)](http://theoryofcomputing.org/articles/v005a011/)] + """ + # Kudos: Based on MatLab code written by Marcus P. da Silva + # (https://github.com/BBN-Q/matlab-diamond-norm/) + import cvxpy as cvx + + if set(chan0.qubits) != set(chan1.qubits): + raise ValueError("Channels must operate on same qubits") + + if chan0.qubits != chan1.qubits: + chan1 = chan1.permute(chan0.qubits) + + N = chan0.qubit_nb + dim = 2 ** N + + choi0 = chan0.choi() + choi1 = chan1.choi() + + delta_choi = choi0 - choi1 + + # Density matrix must be Hermitian, positive semidefinite, trace 1 + rho = cvx.Variable([dim, dim], complex=True) + constraints = [rho == rho.H] + constraints += [rho >> 0] + constraints += [cvx.trace(rho) == 1] + + # W must be Hermitian, positive semidefinite + W = cvx.Variable([dim ** 2, dim ** 2], complex=True) + constraints += [W == W.H] + constraints += [W >> 0] + + constraints += [(W - cvx.kron(np.eye(dim), rho)) << 0] + + J = cvx.Parameter([dim ** 2, dim ** 2], complex=True) + objective = cvx.Maximize(cvx.real(cvx.trace(J.H * W))) + + prob = cvx.Problem(objective, constraints) + + J.value = delta_choi + prob.solve() + + dnorm = prob.value * 2 + + # Diamond norm is between 0 and 2. Correct for floating point errors + dnorm = min(2, dnorm) + dnorm = max(0, dnorm) + + return dnorm + + +# fin diff --git a/qf_diamond_norm/info_test.py b/qf_diamond_norm/info_test.py new file mode 100644 index 0000000..cfad074 --- /dev/null +++ b/qf_diamond_norm/info_test.py @@ -0,0 +1,76 @@ +# Copyright 2020-, Gavin E. Crooks and contributors +# +# This source code is licensed under the Apache License, Version 2.0 found in +# the LICENSE.txt file in the root directory of this source tree. + +import numpy as np +import pytest +import quantumflow as qf + +from qf_diamond_norm import diamond_norm + + +def test_diamond_norm() -> None: + # Test cases borrowed from qutip, + # https://github.com/qutip/qutip/blob/master/qutip/tests/test_metrics.py + # which were in turn generated using QuantumUtils for MATLAB + # (https://goo.gl/oWXhO9) + + RTOL = 0.01 + chan0 = qf.I(0).aschannel() + chan1 = qf.X(0).aschannel() + dn = diamond_norm(chan0, chan1) + assert np.isclose(2.0, dn, rtol=RTOL) + + turns_dnorm = [ + [1.000000e-03, 3.141591e-03], + [3.100000e-03, 9.738899e-03], + [1.000000e-02, 3.141463e-02], + [3.100000e-02, 9.735089e-02], + [1.000000e-01, 3.128689e-01], + [3.100000e-01, 9.358596e-01], + ] + + for turns, target in turns_dnorm: + chan0 = qf.XPow(0.0, 0).aschannel() + chan1 = qf.XPow(turns, 0).aschannel() + + dn = diamond_norm(chan0, chan1) + assert np.isclose(target, dn, rtol=RTOL) + + hadamard_mixtures = [ + [1.000000e-03, 2.000000e-03], + [3.100000e-03, 6.200000e-03], + [1.000000e-02, 2.000000e-02], + [3.100000e-02, 6.200000e-02], + [1.000000e-01, 2.000000e-01], + [3.100000e-01, 6.200000e-01], + ] + + for p, target in hadamard_mixtures: + tensor = qf.I(0).aschannel().tensor * (1 - p) + qf.H(0).aschannel().tensor * p + chan0 = qf.Channel(tensor, [0]) + + chan1 = qf.I(0).aschannel() + + dn = diamond_norm(chan0, chan1) + assert np.isclose(dn, target, rtol=RTOL) + + chan0 = qf.YPow(0.5, 0).aschannel() + chan1 = qf.I(0).aschannel() + dn = diamond_norm(chan0, chan1) + assert np.isclose(dn, np.sqrt(2), rtol=RTOL) + + chan0 = qf.CNot(0, 1).aschannel() + chan1 = qf.CNot(1, 0).aschannel() + diamond_norm(chan0, chan1) + + +def test_diamond_norm_err() -> None: + with pytest.raises(ValueError): + chan0 = qf.I(0).aschannel() + chan1 = qf.I(1).aschannel() + diamond_norm(chan0, chan1) + + +# fin diff --git a/setup.cfg b/setup.cfg index e809114..f6d4ad7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,11 +3,11 @@ # [INI](https://docs.python.org/3/install/index.html#inst-config-syntax) file format. [metadata] -name = gecrooks_python_template -url = https://github.com/gecrooks/gecrooks-python-template/ +name = qf_diamond_norm +url = https://github.com/gecrooks/qf-diamond-norm/ author = Gavin Crooks -author_email = gavincrooks@gmail.com -description = "Minimal Viable Product for an open source, github hosted, python package" +author_email = gec@threeplusone.com +description = "The diamond norm between two completely positive trace-preserving (CPTP) superoperators" long_description = file:README.md long_description_content_type = text/markdown license_file = LICENSE @@ -35,7 +35,8 @@ python_requires = >= 3.7 # importlib_metadata required for python 3.7 install_requires = importlib_metadata - numpy + quantumflow + cvxpy setup_requires = setuptools_scm @@ -56,7 +57,7 @@ dev = # pytest configuration [tool:pytest] testpaths = - gecrooks_python_template + qf_diamond_norm # Configuration for test coverage @@ -67,7 +68,7 @@ testpaths = [coverage:paths] source = - gecrooks_python_template + qf_diamond_norm [coverage:run] omit = @@ -93,7 +94,7 @@ ignore = E203, W503 # https://mypy.readthedocs.io/en/stable/config_file.html [mypy] -files = gecrooks_python_template +files = qf_diamond_norm # Suppresses error about unresolved imports (i.e. from numpy) ignore_missing_imports = True From 0ef2caac54e7662400485e216466dd3d22b82bf9 Mon Sep 17 00:00:00 2001 From: gecrooks Date: Fri, 11 Dec 2020 19:49:13 -0800 Subject: [PATCH 02/11] Minor tweaks --- qf_diamond_norm/config.py | 14 ++++++-------- setup.cfg | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/qf_diamond_norm/config.py b/qf_diamond_norm/config.py index 079d977..ad94913 100644 --- a/qf_diamond_norm/config.py +++ b/qf_diamond_norm/config.py @@ -23,10 +23,8 @@ __all__ = ["__version__", "about"] -package_name = "qf_diamond_norm" - try: - __version__ = importlib_metadata.version(package_name) # type: ignore + __version__ = importlib_metadata.version(__package__) # type: ignore except Exception: # pragma: no cover # package is not installed __version__ = "?.?.?" @@ -35,12 +33,12 @@ def about(file: typing.TextIO = None) -> None: f"""Print information about the package - ``> python -m {package_name}.about`` + ``> python -m {__package__}.about`` Args: file: Output stream (Defaults to stdout) """ - metadata = importlib_metadata.metadata(package_name) # type: ignore + metadata = importlib_metadata.metadata(__package__) # type: ignore print(f"# {metadata['Name']}", file=file) print(f"{metadata['Summary']}", file=file) print(f"{metadata['Home-page']}", file=file) @@ -48,10 +46,10 @@ def about(file: typing.TextIO = None) -> None: name_width = 24 versions = {} versions["platform"] = platform.platform(aliased=True) - versions[package_name] = __version__ + versions[__package__] = __version__ versions["python"] = sys.version[0:5] - for req in importlib_metadata.requires(package_name): # type: ignore + for req in importlib_metadata.requires(__package__): # type: ignore name = re.split("[; =><]", req)[0] try: versions[name] = importlib_metadata.version(name) # type: ignore @@ -59,7 +57,7 @@ def about(file: typing.TextIO = None) -> None: pass print(file=file) - print(f"# Configuration", file=file) + print("# Configuration", file=file) for name, vers in versions.items(): print(name.ljust(name_width), vers, file=file) print(file=file) diff --git a/setup.cfg b/setup.cfg index f6d4ad7..feb3158 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,7 +7,7 @@ name = qf_diamond_norm url = https://github.com/gecrooks/qf-diamond-norm/ author = Gavin Crooks author_email = gec@threeplusone.com -description = "The diamond norm between two completely positive trace-preserving (CPTP) superoperators" +description = The diamond norm between two completely positive trace-preserving (CPTP) superoperators long_description = file:README.md long_description_content_type = text/markdown license_file = LICENSE From d481ae778b0c5b8d48b23f0c4c0002c9b3c532f4 Mon Sep 17 00:00:00 2001 From: gecrooks Date: Fri, 11 Dec 2020 19:58:54 -0800 Subject: [PATCH 03/11] Add python 3.9 support --- .github/workflows/python-build.yml | 2 +- setup.cfg | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-build.yml b/.github/workflows/python-build.yml index 13235d6..13c9cba 100644 --- a/.github/workflows/python-build.yml +++ b/.github/workflows/python-build.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7', '3.8'] + python-version: ['3.7', '3.8', '3.9'] steps: - uses: actions/checkout@v2 diff --git a/setup.cfg b/setup.cfg index feb3158..45e6f04 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,6 +25,7 @@ classifiers= Programming Language :: Python :: 3 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 Operating System :: OS Independent From d14c8c7ca00628684926643f4b77bc6b86e69d62 Mon Sep 17 00:00:00 2001 From: gecrooks Date: Fri, 11 Dec 2020 21:09:59 -0800 Subject: [PATCH 04/11] Add conda install to build workflow --- qf_diamond_norm/about.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qf_diamond_norm/about.py b/qf_diamond_norm/about.py index 174b102..7de4259 100644 --- a/qf_diamond_norm/about.py +++ b/qf_diamond_norm/about.py @@ -1,6 +1,6 @@ # Copyright 2019-2021, Gavin E. Crooks and contributors # -# This source code is licensed under the Apache License, Version 2.0 found in +# This source code is licensed under the Apache License 2.0 found in # the LICENSE.txt file in the root directory of this source tree. # Command line interface for the about() function From b90a3cd39eaa05877817e91fd8d903941180f2d9 Mon Sep 17 00:00:00 2001 From: gecrooks Date: Fri, 11 Dec 2020 21:16:42 -0800 Subject: [PATCH 05/11] Add conda install to build workflow --- .github/workflows/python-build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-build.yml b/.github/workflows/python-build.yml index 13c9cba..885c1cb 100644 --- a/.github/workflows/python-build.yml +++ b/.github/workflows/python-build.yml @@ -26,6 +26,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | + conda install -c conda-forge cvxpy python -m pip install --upgrade pip if [ -f requirements.txt ]; then pip install -r requirements.txt; fi python -m pip install .[dev] # install package + test dependencies From be4ad62aa4e80d2752d9fee170e578e5d5c384fb Mon Sep 17 00:00:00 2001 From: gecrooks Date: Fri, 11 Dec 2020 21:17:13 -0800 Subject: [PATCH 06/11] Update metadata --- qf_diamond_norm/__init__.py | 2 +- qf_diamond_norm/config.py | 2 +- qf_diamond_norm/config_test.py | 2 +- qf_diamond_norm/info.py | 2 +- qf_diamond_norm/info_test.py | 2 +- setup.cfg | 42 ++++++++++++++++++---------------- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/qf_diamond_norm/__init__.py b/qf_diamond_norm/__init__.py index ecdf2b1..fb2d4eb 100644 --- a/qf_diamond_norm/__init__.py +++ b/qf_diamond_norm/__init__.py @@ -1,6 +1,6 @@ # Copyright 2019-2021, Gavin E. Crooks and contributors # -# This source code is licensed under the Apache License, Version 2.0 found in +# This source code is licensed under the Apache License 2.0 found in # the LICENSE.txt file in the root directory of this source tree. from .config import __version__ # noqa: F401 diff --git a/qf_diamond_norm/config.py b/qf_diamond_norm/config.py index ad94913..e97c992 100644 --- a/qf_diamond_norm/config.py +++ b/qf_diamond_norm/config.py @@ -1,6 +1,6 @@ # Copyright 2019-2021, Gavin E. Crooks and contributors # -# This source code is licensed under the Apache License, Version 2.0 found in +# This source code is licensed under the Apache License 2.0 found in # the LICENSE.txt file in the root directory of this source tree. """ diff --git a/qf_diamond_norm/config_test.py b/qf_diamond_norm/config_test.py index 5fa413c..e55b3d8 100644 --- a/qf_diamond_norm/config_test.py +++ b/qf_diamond_norm/config_test.py @@ -1,6 +1,6 @@ # Copyright 2019-2021, Gavin E. Crooks and contributors # -# This source code is licensed under the Apache License, Version 2.0 found in +# This source code is licensed under the Apache License 2.0 found in # the LICENSE.txt file in the root directory of this source tree. import glob diff --git a/qf_diamond_norm/info.py b/qf_diamond_norm/info.py index ceaf66e..2143467 100644 --- a/qf_diamond_norm/info.py +++ b/qf_diamond_norm/info.py @@ -1,6 +1,6 @@ # Copyright 2020-, Gavin E. Crooks and contributors # -# This source code is licensed under the Apache License, Version 2.0 found in +# This source code is licensed under the Apache License 2.0 found in # the LICENSE.txt file in the root directory of this source tree. diff --git a/qf_diamond_norm/info_test.py b/qf_diamond_norm/info_test.py index cfad074..22b4596 100644 --- a/qf_diamond_norm/info_test.py +++ b/qf_diamond_norm/info_test.py @@ -1,6 +1,6 @@ # Copyright 2020-, Gavin E. Crooks and contributors # -# This source code is licensed under the Apache License, Version 2.0 found in +# This source code is licensed under the Apache License 2.0 found in # the LICENSE.txt file in the root directory of this source tree. import numpy as np diff --git a/setup.cfg b/setup.cfg index 45e6f04..fda2a36 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,31 +3,33 @@ # [INI](https://docs.python.org/3/install/index.html#inst-config-syntax) file format. [metadata] -name = qf_diamond_norm -url = https://github.com/gecrooks/qf-diamond-norm/ -author = Gavin Crooks -author_email = gec@threeplusone.com -description = The diamond norm between two completely positive trace-preserving (CPTP) superoperators -long_description = file:README.md -long_description_content_type = text/markdown -license_file = LICENSE -license = Apache-2.0 - -classifiers= - Development Status :: 4 - Beta +Metadata-Version: 2.2 +Name = qf_diamond_norm +Summary = The diamond norm between two completely positive trace-preserving (CPTP) superoperators +Description = file:README.md +Description-Content-Type = text/markdown +Keywords = python,template +Home-page = https://github.com/gecrooks/qf-diamond-norm/ +Author = Gavin E. Crooks +Author-email = gec@threeplusone.com +License = Apache-2.0 # SPDX license short-form identifier, https://spdx.org/licenses/ +License-File = LICENSE + +# https://pypi.org/classifiers/ +Classifiers= + Development Status :: 5 - Stable Intended Audience :: Science/Research - License :: OSI Approved :: Apache Software License - Topic :: Scientific/Engineering Programming Language :: Python Natural Language :: English - Topic :: Software Development :: Libraries - Topic :: Software Development :: Libraries :: Python Modules + Operating System :: OS Independent Programming Language :: Python :: 3 - Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Operating System :: OS Independent - + Programming Language :: Python :: 3.9 + Topic :: Scientific/Engineering + Topic :: Software Development :: Libraries + Topic :: Software Development :: Libraries :: Python Modules + Typing :: Typed [options] zip_safe = True From 5dcbde757a9e299490eff342cc81bef6ef4209c7 Mon Sep 17 00:00:00 2001 From: gecrooks Date: Fri, 11 Dec 2020 21:26:31 -0800 Subject: [PATCH 07/11] tests... --- .github/workflows/python-build.yml | 2 +- requirements.txt | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 requirements.txt diff --git a/.github/workflows/python-build.yml b/.github/workflows/python-build.yml index 885c1cb..c616b9f 100644 --- a/.github/workflows/python-build.yml +++ b/.github/workflows/python-build.yml @@ -29,7 +29,7 @@ jobs: conda install -c conda-forge cvxpy python -m pip install --upgrade pip if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - python -m pip install .[dev] # install package + test dependencies + # python -m pip install .[dev] # install package + test dependencies - name: About run: | python -m $(python -Wi setup.py --name).about diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9db0fd2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,13 @@ +importlib_metadata +quantumflow +# cvxpy +# setuptools_scm +pytest >= 4.6 +pytest-cov +flake8 +mypy +black +isort +sphinx +sphinxcontrib-bibtex +setuptools_scm From 178d4dcbe06a88c50dec3b3c4d34fe2f8395b59d Mon Sep 17 00:00:00 2001 From: gecrooks Date: Fri, 11 Dec 2020 21:30:52 -0800 Subject: [PATCH 08/11] tests... --- .github/workflows/python-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-build.yml b/.github/workflows/python-build.yml index c616b9f..a4c7f04 100644 --- a/.github/workflows/python-build.yml +++ b/.github/workflows/python-build.yml @@ -29,7 +29,7 @@ jobs: conda install -c conda-forge cvxpy python -m pip install --upgrade pip if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - # python -m pip install .[dev] # install package + test dependencies + python -m pip install . - name: About run: | python -m $(python -Wi setup.py --name).about From 7786313443f4c959fb0f2e1da3cce509a5fb3964 Mon Sep 17 00:00:00 2001 From: gecrooks Date: Fri, 11 Dec 2020 21:34:36 -0800 Subject: [PATCH 09/11] tests... --- requirements.txt | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 9db0fd2..0000000 --- a/requirements.txt +++ /dev/null @@ -1,13 +0,0 @@ -importlib_metadata -quantumflow -# cvxpy -# setuptools_scm -pytest >= 4.6 -pytest-cov -flake8 -mypy -black -isort -sphinx -sphinxcontrib-bibtex -setuptools_scm From 5e713cfd51f9a02cae1de5aaa6dc2530ecae0e75 Mon Sep 17 00:00:00 2001 From: gecrooks Date: Fri, 11 Dec 2020 21:40:01 -0800 Subject: [PATCH 10/11] tests... --- .github/workflows/python-build.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-build.yml b/.github/workflows/python-build.yml index a4c7f04..f53637c 100644 --- a/.github/workflows/python-build.yml +++ b/.github/workflows/python-build.yml @@ -28,7 +28,21 @@ jobs: run: | conda install -c conda-forge cvxpy python -m pip install --upgrade pip - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + python -m pip install importlib_metadata + python -m pip install quantumflow + # python -m pip install cvxpy + python -m pip install pytest >= 4.6 + python -m pip install pytest-cov + python -m pip install flake8 + python -m pip install mypy + python -m pip install black + python -m pip install isort + python -m pip install sphinx + python -m pip install sphinxcontrib-bibtex + python -m pip install setuptools_scm + python -m pip install . - name: About run: | From 163cfce584765aa73cb39ae15f328cc9c334c5c2 Mon Sep 17 00:00:00 2001 From: gecrooks Date: Fri, 11 Dec 2020 21:44:13 -0800 Subject: [PATCH 11/11] tests... --- .github/workflows/python-build.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/python-build.yml b/.github/workflows/python-build.yml index f53637c..d3b1520 100644 --- a/.github/workflows/python-build.yml +++ b/.github/workflows/python-build.yml @@ -33,15 +33,7 @@ jobs: python -m pip install importlib_metadata python -m pip install quantumflow # python -m pip install cvxpy - python -m pip install pytest >= 4.6 - python -m pip install pytest-cov - python -m pip install flake8 - python -m pip install mypy - python -m pip install black - python -m pip install isort - python -m pip install sphinx - python -m pip install sphinxcontrib-bibtex - python -m pip install setuptools_scm + python -m pip install pytest pytest-cov flake8 mypy black isort sphinx sphinxcontrib-bibtex setuptools_scm python -m pip install . - name: About