Skip to content

Commit

Permalink
Merge branch 'main' into ds/timedep_port
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmoutinho committed Aug 8, 2024
2 parents 606959c + a4b6e1a commit fe71257
Show file tree
Hide file tree
Showing 50 changed files with 4,449 additions and 2,568 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Linting

on:
push:
branches:
- main
pull_request: {}
workflow_dispatch: {}

jobs:
lint:
name: Linting
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- name: Checkout main code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install pre-commit
run: |
pip install pre-commit
pre-commit install
- name: Check files and lint
run: |
pre-commit run --all-files
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Linting / Tests / Documentation
name: Tests

on:
push:
Expand All @@ -16,29 +16,6 @@ concurrency:
cancel-in-progress: true

jobs:
lint:
name: Linting
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- name: Checkout main code and submodules
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install hatch
run: |
python -m pip install hatch
- name: Install main dependencies
run: |
python -m hatch -v -e tests
- name: Lint
run: |
python -m hatch -e tests run pre-commit run --all-files
unit_tests:
name: Unit testing
runs-on: ubuntu-latest
Expand All @@ -49,21 +26,19 @@ jobs:
- name: Checkout main code and submodules
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install hatch
run: |
python -m pip install hatch
- name: Install main dependencies
run: |
python -m hatch -v -e tests
- name: Lint
pip install --upgrade pip
pip install hatch
- name: Install main dependencies in test env
run: |
python -m hatch -e tests run pre-commit run --all-files
hatch -v -e tests
- name: Perform unit tests
run: |
python -m hatch -e tests run pytest -n auto
hatch -e tests run pytest -n auto
test_docs:
name: Documentation
Expand All @@ -75,41 +50,46 @@ jobs:
- name: Checkout main code and submodules
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install hatch
run: |
python -m pip install hatch
pip install --upgrade pip
pip install hatch
- name: Install main dependencies
run: |
python -m hatch -v -e docs
hatch -v -e docs
- name: Test docs
run: |
python -m hatch run docs:build
hatch run docs:build
publish:
name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags/v')
needs: unit_tests
runs-on: ubuntu-latest
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- name: Checkout main code and submodules
- name: Checkout main code
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade pip
pip install hatch
- name: Build and publish package
- name: Build package
run: |
hatch build
hatch publish -u __token__ -a ${{ secrets.PYPI_API_TOKEN }}
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Confirm deployment
timeout-minutes: 5
run: |
Expand All @@ -123,17 +103,28 @@ jobs:
deploy_docs:
name: Deploy documentation
if: startsWith(github.ref, 'refs/tags/v')
needs: unit_tests
needs: [unit_tests, test_docs]
runs-on: ubuntu-latest
steps:
- name: Checkout main code and submodules
- name: Checkout main code
uses: actions/checkout@v4
- name: Install JetBrains Mono font
run: |
sudo apt install -y wget unzip fontconfig
wget https://download.jetbrains.com/fonts/JetBrainsMono-2.304.zip
unzip JetBrainsMono-2.304.zip -d JetBrainsMono
mkdir -p /usr/share/fonts/truetype/jetbrains
cp JetBrainsMono/fonts/ttf/*.ttf /usr/share/fonts/truetype/jetbrains/
fc-cache -f -v
- name: Install graphviz
run: sudo apt-get install -y graphviz
- name: Set up Python 3.10
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Hatch
run: |
pip install --upgrade pip
pip install hatch
- name: Deploy docs
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
It acts as the main backend for [`Qadence`](https://github.com/pasqal-io/qadence), a digital-analog quantum programming interface.
`pyqtorch` allows for writing fully differentiable quantum programs using both digital and analog operations; enabled via a intuitive, torch-based syntax.

[![Linting / Tests/ Documentation](https://github.com/pasqal-io/pyqtorch/actions/workflows/run-tests-and-mypy.yml/badge.svg)](https://github.com/pasqal-io/pyqtorch/actions/workflows/run-tests-and-mypy.yml)
[![Linting / Tests/ Documentation](https://github.com/pasqal-io/pyqtorch/actions/workflows/test.yml/badge.svg)](https://github.com/pasqal-io/pyqtorch/actions/workflows/test.yml)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Pypi](https://badge.fury.io/py/pyqtorch.svg)](https://pypi.org/project/pyqtorch/)

Expand Down
3 changes: 3 additions & 0 deletions docs/analog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

An analog operation is one whose unitary is best described by the evolution of some hermitian generator, or Hamiltonian, acting on an arbitrary number of qubits. For a time-independent generator $\mathcal{H}$ and some time variable $t$, the evolution operator is $\exp(-i\mathcal{H}t)$. `pyqtorch` provides the HamiltonianEvolution class to initialize analog operations. There exists several ways to pass a generator, and we present them next.

!!! warning "Dimensionless units"
The quantity $\mathcal{H}t$ has to be **dimensionless** for exponentiation in PyQTorch.

### Tensor generator

The first case of generator we can provide is simply an arbitrary hermitian tensor.
Expand Down
15 changes: 7 additions & 8 deletions docs/differentiation.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ The [adjoint differentiation mode](https://arxiv.org/abs/2009.02823) computes fi
The Generalized parameter shift rule (GPSR mode) is an extension of the well known [parameter shift rule (PSR)](https://arxiv.org/abs/1811.11184) algorithm [to arbitrary quantum operations](https://arxiv.org/abs/2108.01218). Indeed, PSR only works for quantum operations whose generator has a single gap in its eigenvalue spectrum, GPSR extending to multi-gap.

!!! warning "Usage restrictions"
At the moment, only operations with two distinct eigenvalues
from their generator (single gap shift rule) are supported. The multi gap case
will be supported in a later release.
Circuits with one or more Scale or HamiltonianEvolution operations are not supported.
Finally, circuits with operations sharing a same parameter name
are also not supported.
At the moment, circuits with one or more Scale or HamiltonianEvolution operations are not supported.
They should be handled differently as GPSR requires operations to be of the form presented below.
Also, circuits with operations sharing a same parameter name are also not supported
as such cases are handled by our other Python package for differentiable digital-analog quantum programs Qadence
which uses pyqtorch as a backend. Qadence convert circuits to use different parameter names when applying GPSR.

For this, we define the differentiable function as quantum expectation value

Expand Down Expand Up @@ -56,11 +55,11 @@ batch_size = 1

ry = pyq.RY(0, param_name="x")
cnot = pyq.CNOT(1, 2)
ops = [ry]
ops = [ry, cnot]
n_qubits = 3
circ = pyq.QuantumCircuit(n_qubits, ops)

obs = pyq.QuantumCircuit(n_qubits, [pyq.Z(0)])
obs = pyq.Observable(pyq.Z(0))
state = pyq.zero_state(n_qubits)

values_ad = {"x": torch.tensor([torch.pi / 2], requires_grad=True)}
Expand Down
Loading

0 comments on commit fe71257

Please sign in to comment.