This document is a summary of how to do various tasks one runs into as a developer of cirq. Note that all commands assume a Debian environment, and all commands (except the initial repository cloning command) assume you are at the cirq repo root.
You can create a local version of this repository by running:
```bash
git clone [email protected]:quantumlib/Cirq.git
cd Cirq
```
This will allow you to use the Cirq library and build your own applications using this framework.
If instead, you wish to do development on Cirq itself and contribute back to the community, follow the directions below.
If do not plan to contribute back to the Cirq project and only wish to use the Cirq framework to build your own quantum programs and circuits, you can skip this section.
- Fork the Cirq repo (Fork button in upper right corner of
repo page).
Forking creates a new github repo at the location
https://github.com/USERNAME/cirq
whereUSERNAME
is your github id. - Clone the fork you created to your local machine at the directory
where you would like to store your local copy of the code.
(Alternatively, you can clone the repository using the URL provided on your repo page under the green "Clone or Download" button)
git clone [email protected]:USERNAME/cirq.git
- Add a remote called
upstream
to git. This remote will represent the main git repo for cirq (as opposed to the clone, which you just created, which will be theorigin
remote). This remote can be used to sync your local git repos with the main git repo for cirq.To verify the remote rungit remote add upstream https://github.com/quantumlib/cirq.git
git remote -v
and you should see both theorigin
andupstream
remotes. - Sync up your local git with the
upstream
remote:You can check the branches that are on thegit fetch upstream
upstream
remote by runninggit remote -va
orgit branch -r
. Most importantly you should seeupstream/master
listed. - Merge the upstream master into your local master so that
it is up to date
At this point your local git master should be synced with the master from the main cirq repo.
git checkout master git merge upstream/master
-
First clone the repository, if you have not already done so. See the previous section for instructions.
-
Install system dependencies.
Make sure you have python 3.5 or greater. You can install most other dependencies via
apt-get
:cat apt-dev-requirements.txt apt-runtime-requirements.txt | xargs sudo apt-get install --yes
Unfortunately, as of this writing, v3.5 of the protobuf compiler is not installable via
apt-get
. You can skip this dependency. It is only needed when producing the transpiled python 2.7 code for local testing. The installation process is technical; requiring you to either build from source or manually installing pre-built binaries onto your system. If you want to be able to run the python 2.7 tests on your machine, see "Protobuf Compiler Installation" on the google/protobuf github repository for details. -
Prepare a virtual environment with the dev requirements.
One of the system dependencies we installed was
virtualenvwrapper
, which makes it easy to create virtual environment. If you did not havevirtualenvwrapper
previously, you may need to re-open your terminal or runsource ~/.bashrc
before these commands will work:mkvirtualenv cirq-py3 --python=/usr/bin/python3 pip install --upgrade pip pip install -r dev-requirements.txt
(When you later open another terminal, you can activate the virtualenv with
workon cirq-py3
.) -
Check that the tests pass.
pytest .
-
(OPTIONAL) include your development copy of cirq in your python path.
PYTHONPATH="$(pwd)":"${PYTHONPATH}"
There are two options, one easy/fast and the other slow/reliable.
Run continuous-integration/simple_check.sh to invoke pylint
, mypy
, and pytest
directly on your working directory.
This check does not attempt to ensure your test environment is up to date, and it does not transpile and test the python 2 code.
bash continuous-integration/simple_check.sh
Run continuous-integration/check.sh to run the checks inside a temporary fresh virtual environment and to also transpile and test the python 2 code.
bash continuous-integration/check.sh
You can run a subset of the checks using the --only
flag.
This flag value can be pylint
, typecheck
, pytest
, pytest2
,
or incremental-coverage
.
Run python2.7-generate.sh to transpile cirq's python 3 code into python 2.7 code:
bash python2.7-generate.sh [output_dir] [input_dir] [virtual_env_with_3to2]
If you don't specify any arguments then the input directory will be the current
working directory, the output directory will be python2.7-output
within the
current directory, and 3to2
will be invoked in the current environment.
The script does nothing if the output directory already exists.
-
Set the version numbers in cirq/_version.py.
The python 3 version should end with
.35
whereas the python 2 version should end with.27
. For example:0.0.4.35
is the python 3 variant of version0.0.4
.pip
will choose between the two based on whichever version of python the user is using. Development versions end with.dev35
and.dev27
instead of.35
and.27
, e.g. use0.0.4.dev27
for the python 2 variant of the development version of0.0.4
. -
Run dev_tools/prepare-package.sh to produce pypi artifacts.
bash dev_tools/produce-package.sh
The output files will be placed in
dist/
, from which they can be uploaded to pypi with a tool such astwine
.