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

[Release] Bump to 1.0.0 #19

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
6377bc9
constructors
jpmoutinho Oct 2, 2023
383c6f1
Digital decomposition, operations and Braket backend
Oct 2, 2023
15c475e
Add measurements.
RolandMacDoland Oct 2, 2023
cd533af
Merge branch 'main' into jm/constructors
jpmoutinho Oct 2, 2023
9c28a60
Merge pull request #11 from pasqal-io/jm/constructors
jpmoutinho Oct 2, 2023
0a63666
Merge pull request #12 from pasqal-io/md/contribution
madagra Oct 2, 2023
f2a491f
dominik files
dominikandreasseitz Oct 2, 2023
bae5688
pyqtorch; draw; models; transpile
nmheim Oct 2, 2023
e6835e9
Merge pull request #13 from pasqal-io/ds/dominik
dominikandreasseitz Oct 2, 2023
145ef6b
Added infrastructure and build files
Oct 2, 2023
b8ee23a
Cleanup
dominikandreasseitz Oct 2, 2023
943dece
block_to_tensor
dominikandreasseitz Oct 2, 2023
9192e8b
matrixblock
dominikandreasseitz Oct 2, 2023
bc48393
add utils.py file
Oct 2, 2023
c2b6b6f
new draw; more blocks
nmheim Oct 2, 2023
35163e5
Merge pull request #14 from pasqal-io/em/blocks_utils
Doomsk Oct 2, 2023
dd4e621
Add README. (#15)
RolandMacDoland Oct 2, 2023
cf5b3fb
remaining backends files
dominikandreasseitz Oct 2, 2023
560b3c2
Rg/add readme (#16)
RolandMacDoland Oct 2, 2023
1f1c65d
gpsr algorithm
vytautas-a Oct 2, 2023
73825cf
pulser backend
vytautas-a Oct 2, 2023
a85c79b
draw requirements; install instructions
nmheim Oct 2, 2023
c1c4461
Merge branch 'main' of github.com:pasqal-io/qadence
nmheim Oct 2, 2023
c36f97b
Remove refs to private repo.
RolandMacDoland Oct 2, 2023
d73b9a1
Create a coverage report as XML file.
RolandMacDoland Oct 2, 2023
7735a80
Added main utility modules
Oct 2, 2023
6d785c7
Added main utility modules
Oct 2, 2023
e87857c
Update pyproject.toml
jpmoutinho Oct 2, 2023
14ea1e5
added co-author
vytautas-a Oct 2, 2023
24120f7
Added abstract block
Oct 2, 2023
a147753
Merge branch 'main' of github.com:pasqal-io/qadence
dominikandreasseitz Oct 2, 2023
5469129
Add pytorchwrapper and embedding.
dominikandreasseitz Oct 2, 2023
9599fd5
Add errors module. (#17)
RolandMacDoland Oct 2, 2023
5223ce7
Lint on pushes to main.
RolandMacDoland Oct 2, 2023
cd6d3fa
Adjust to new drawing module
dominikandreasseitz Oct 2, 2023
d4ea303
Block transpile fill_identities
dominikandreasseitz Oct 2, 2023
b7deb6a
Remove drawing from abstractblock
dominikandreasseitz Oct 2, 2023
34cadc9
Remove drawing from analogblock
dominikandreasseitz Oct 2, 2023
0d87bda
Remove drawing from compositeblock
dominikandreasseitz Oct 2, 2023
746aa0d
Remove drawing from primitiveblock
dominikandreasseitz Oct 2, 2023
3083768
fix test_circuit
dominikandreasseitz Oct 2, 2023
a25cc4e
Cleanup files
dominikandreasseitz Oct 2, 2023
ae6db09
Rename namespace
dominikandreasseitz Oct 2, 2023
0b64498
bump to 1.0.0
dominikandreasseitz Oct 2, 2023
546a9a7
use pytest-xdist
dominikandreasseitz Oct 2, 2023
d799bb0
Update pre-commits. (#18)
RolandMacDoland Oct 2, 2023
3a30973
Docs, examples, correct expectation shape (#31)
nmheim Oct 3, 2023
2a3a40d
don't exclude py files in docs forlder
nmheim Oct 5, 2023
9271181
Merge branch 'main' into ds/release
dominikandreasseitz Oct 6, 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
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Lint and type check Qadence.

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

Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/test_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ jobs:
test_qadence_ubuntu:
name: Test Qadence (ubuntu)
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.9", "3.10"]
steps:
- uses: actions/checkout@v4
- name: Select Python 3.10
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: ${{ matrix.python-version }}
- name: Install Hatch
run: |
pip install hatch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Qadence example tests.
name: Run Qadence example and notebook tests.

on:
push:
Expand All @@ -9,8 +9,10 @@ on:
- main
paths:
- examples
paths-ignore:
- examples/notebooks
- notebooks
schedule:
# 03:00 every Saturday morning
- cron: '0 3 * * 6'
workflow_dispatch: {}

concurrency:
Expand All @@ -33,3 +35,6 @@ jobs:
- name: Run example tests
run: |
hatch -v run test-examples
- name: Run notebooks tests
run: |
hatch -v run test-notebooks
7 changes: 5 additions & 2 deletions .github/workflows/test_fast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ jobs:
test_qadence_ubuntu:
name: Test Qadence (ubuntu)
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.9", "3.10"]
steps:
- uses: actions/checkout@v4
- name: Select Python 3.10
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: ${{ matrix.python-version }}
- name: Install Hatch
run: |
pip install hatch
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/test_notebooks.yml

This file was deleted.

22 changes: 19 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,28 @@ runs/
# Mkdocs
site/

# converted notebooks
docs/**/*.py

# pt files
*.pt

# event files
events.out.tfevents.*
/examples/notebooks/onboarding_sandbox.ipynb

# latex
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fmt
*.fot
*.cb
*.cb2
*.lb
*.pdf
*.ps
*.dvi

*.gv
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ repos:
args: ['--maxkb=600']

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.0.288"
rev: "v0.0.291"
hooks:
- id: ruff
args: [--fix, --show-fixes, --show-source]
args: [--fix, --show-fixes, --show-source, --exclude, examples/draw.py]

- repo: https://github.com/ambv/black
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black

Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include qadence/gpsr/dfdx_expressions.pkl
include qadence/gpsr/dfdx_variance_expressions.pkl
165 changes: 165 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@

# Qadence

*Qadence* is a Python package that provides a simple interface to build _**digital-analog quantum
programs**_ with tunable interaction defined on _**arbitrary qubit register layouts**_.

[![pre-commit](https://github.com/pasqal-io/qadence/actions/workflows/lint.yml/badge.svg)](https://github.com/pasqal-io/qadence/actions/workflows/lint.yml)
[![tests](https://github.com/pasqal-io/qadence/actions/workflows/test_fast.yml/badge.svg)](https://github.com/pasqal-io/qadence/actions/workflows/test_fast.yml)

## Feature highlights

* A [block-based system](tutorials/getting_started.md) for composing _**complex digital-analog
programs**_ in a flexible and extensible manner. Heavily inspired by
[`Yao.jl`](https://github.com/QuantumBFS/Yao.jl) and functional programming concepts.

* A [simple interface](digital_analog_qc/analog-basics.md) to work with _**interacting qubit systems**_
using [arbitrary qubit registers](tutorials/register.md).

* Intuitive, [expression-based system](tutorials/parameters.md) built on top of `sympy` to construct
_**parametric quantum programs**_.

* [Higher-order generalized parameter shift](link to psr tutorial) rules for _**differentiating
arbitrary quantum operations**_ on real hardware.

* Out-of-the-box automatic differentiability of quantum programs using [https://pytorch.org](https://pytorch.org)

* `QuantumModel`s to make `QuantumCircuit`s differentiable and runnable on a variety of different
backends like state vector simulators, tensor network emulators and real devices.

Documentation can be found here: [https://pasqal-qadence.readthedocs-hosted.com/en/latest](https://pasqal-qadence.readthedocs-hosted.com/en/latest).

## Remarks
Quadence uses torch.float64 as the default datatype for tensors (torch.complex128 for complex tensors).

## Examples

### Bell state

Sample from the [Bell state](https://en.wikipedia.org/wiki/Bell_state) in one line.

```python exec="on" source="material-block" result="json"
import torch # markdown-exec: hide
torch.manual_seed(0) # markdown-exec: hide
from qadence import CNOT, H, chain, sample

xs = sample(chain(H(0), CNOT(0,1)), n_shots=100)
print(xs) # markdown-exec: hide
from qadence.divergences import js_divergence # markdown-exec: hide
from collections import Counter # markdown-exec: hide
js = js_divergence(xs[0], Counter({"00":50, "11":50})) # markdown-exec: hide
assert js < 0.005 # markdown-exec: hide
```


### Perfect state transfer

We can construct a system that admits perfect state transfer between the two edge qubits in a
line of qubits at time $t=\frac{\pi}{\sqrt 2}$.
```python exec="on" source="material-block" result="json"
import torch
from qadence import X, Y, HamEvo, Register, product_state, sample, add

def interaction(i, j):
return 0.5 * (X(i) @ X(j) + Y(i) @ Y(j))

# initial state with left-most qubit in the 1 state
init_state = product_state("100")

# register with qubits in a line
reg = Register.line(n_qubits=3)

# a line hamiltonian
hamiltonian = add(interaction(*edge) for edge in reg.edges)
# which is the same as:
# hamiltonian = interaction(0, 1) + interaction(1, 2)

# define a hamiltonian evolution over t
t = torch.pi/(2**0.5)
evolution = HamEvo(hamiltonian, t)

samples = sample(reg, evolution, state=init_state, n_shots=1)
print(f"{samples = }") # markdown-exec: hide
from collections import Counter # markdown-exec: hide
assert samples[0] == Counter({"001": 1}) # markdown-exec: hide
```


### Digital-analog emulation

Just as easily we can simulate an Ising hamiltonian that includes an interaction term based on the
distance of two qubits. To learn more about digital-analog quantum computing see the
[digital-analog section](/digital_analog_qc/analog-basics.md).
```python exec="on" source="material-block" result="json"
from torch import pi
from qadence import Register, AnalogRX, sample

# global, analog RX block
block = AnalogRX(pi)

# two qubits far apart (practically non-interacting)
reg = Register.from_coordinates([(0,0), (0,15)])
samples = sample(reg, block)
print(f"distance = 15: {samples = }") # markdown-exec: hide
from collections import Counter # markdown-exec: hide
from qadence.divergences import js_divergence # markdown-exec: hide
js = js_divergence(samples[0], Counter({"11": 100})) # markdown-exec: hide
assert js < 0.01 # markdown-exec: hide

# two qubits close together (interacting!)
reg = Register.from_coordinates([(0,0), (0,5)])
samples = sample(reg, AnalogRX(pi))
print(f"distance = 5: {samples = }") # markdown-exec: hide
js = js_divergence(samples[0], Counter({"01":33, "10":33, "00":33, "11":1})) # markdown-exec: hide
assert js < 0.05 # markdown-exec: hide```
```


## Further Resources
For a more comprehensive introduction and advanced topics, we suggest you to
look at the following tutorials:

* [Description of quantum state conventions.](tutorials/state_conventions.md)
* [Basic tutorial](tutorials/getting_started.md) with a lot of detailed information
* Building [digital-analog](digital_analog_qc/analog-basics.md) quantum programs with interacting qubits
* [The sharp bits](tutorials/parameters.md) of creating parametric programs and observables
* [Advanced features](advanced_tutorials) like the low-level backend interface and model extremization
* Building custom [`QuantumModel`](advanced_tutorials/custom-models.md)s

## Installation guide

Qadence can be install with `pip` as follows:

```bash
export TOKEN_USERNAME=MYUSERNAME
export TOKEN_PASSWORD=THEPASSWORD

pip install --extra-index-url "https://${TOKEN_USERNAME}:${TOKEN_PASSWORD}@gitlab.pasqal.com/api/v4/projects/190/packages/pypi/simple" qadence[pulser,visualization]
```

where the token username and password can be generated on the
[Gitlab UI](https://gitlab.pasqal.com/-/profile/personal_access_tokens). Remember to give registry read/write permissions to the generated token.

The default backend for qadence is pyqtorch (a differentiable state vector simulator).
You can install one or all of the following additional backends and the circuit visualization library using the following extras:

* `braket`: install the Amazon Braket quantum backend
* `emu-c`: install the Pasqal circuit tensor network emulator EMU-C
* `pulser`: install the Pulser backend. Pulser is a framework for composing, simulating and executing pulse sequences for neutral-atom quantum devices.
* `visualization`: install the library necessary to visualize quantum circuits.

!!! warning
In order to correctly install the "visualization" extra, you need to have `graphviz` installed
in your system. This depends on the operating system you are using:

```bash
# on Ubuntu
sudo apt install graphviz

# on MacOS
brew install graphviz

# via conda
conda install python-graphviz
```
---
Loading