Skip to content

Commit

Permalink
Merge pull request #62 from CQCL/develop
Browse files Browse the repository at this point in the history
0.3.2
  • Loading branch information
SamDuffield authored Jan 24, 2023
2 parents 67a5730 + cea2124 commit 2dc1668
Show file tree
Hide file tree
Showing 9 changed files with 1,372 additions and 118 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ param_to_st = qujax.get_params_to_statetensor_func(circuit_gates,
We now have a pure JAX function that generates the statetensor for given parameters
```python
param_to_st(jnp.array([0.1]))
# DeviceArray([[0.58778524+0.j, 0. +0.j],
# [0.80901706+0.j, 0. +0.j]], dtype=complex64)
# Array([[0.58778524+0.j, 0. +0.j],
# [0.80901706+0.j, 0. +0.j]], dtype=complex64)
```

The statevector can be obtained from the statetensor via ```.flatten()```.
```python
param_to_st(jnp.array([0.1])).flatten()
# DeviceArray([0.58778524+0.j, 0.+0.j, 0.80901706+0.j, 0.+0.j], dtype=complex64)
# Array([0.58778524+0.j, 0.+0.j, 0.80901706+0.j, 0.+0.j], dtype=complex64)
```

We can also use qujax to map the statetensor to an expected value
Expand All @@ -70,8 +70,8 @@ from jax import value_and_grad
param_to_expectation = lambda param: st_to_expectation(param_to_st(param))
expectation_and_grad = value_and_grad(param_to_expectation)
expectation_and_grad(jnp.array([0.1]))
# (DeviceArray(-0.3090171, dtype=float32),
# DeviceArray([-2.987832], dtype=float32))
# (Array(-0.3090171, dtype=float32),
# Array([-2.987832], dtype=float32))
```

## Densitytensor simulations with qujax
Expand All @@ -91,7 +91,7 @@ Expectations can also be evaluated through the densitytensor
```python
dt_to_expectation = qujax.get_densitytensor_to_expectation_func([['Z']], [[0]], [1.])
dt_to_expectation(dt)
# DeviceArray(-0.3090171, dtype=float32)
# Array(-0.3090171, dtype=float32)
```
Again everything is differentiable, jit-able and can be composed with other JAX code.

Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ In this directory, you can find a selection of notebooks demonstrating some simp
- [`generative_modelling.ipynb`](https://github.com/CQCL/qujax/blob/main/examples/generative_modelling.ipynb) - uses a parameterised quantum circuit as a generative model for a real life dataset. Trains via stochastic gradient Langevin dynamics on the maximum mean discrepancy between statetensor and dataset.
- [`heisenberg_vqe.ipynb`](https://github.com/CQCL/qujax/blob/main/examples/heisenberg_vqe.ipynb) - an implementation of the variational quantum eigensolver to find the ground state of a quantum Hamiltonian.
- [`maxcut_vqe.ipynb`](https://github.com/CQCL/qujax/blob/main/examples/maxcut_vqe.ipynb) - an implementation of the variational quantum eigensolver to solve a maxcut problem. Trains with Adam via [`optax`](https://github.com/deepmind/optax) and uses more realistic stochastic parameter shift gradients.
- [`noise_channel.ipynb`](https://github.com/CQCL/qujax/blob/main/examples/noise_channel.ipynb) - uses the densitytensor simulator to fit the parameters of a depolarising noise channel.
- [`qaoa.ipynb`](https://github.com/CQCL/qujax/blob/main/examples/qaoa.ipynb) - uses a problem inspired QAOA ansatz to find the ground state of a quantum Hamiltonian. Demonstrates how to encode more sophisticated parameters that control multiple gates.
- [`variational_inference.ipynb`](https://github.com/CQCL/qujax/blob/main/examples/variational_inference.ipynb) - uses a parameterised quantum circuit as a variational distribution to fit to a target probability mass function. Uses Adam via [`optax`](https://github.com/deepmind/optax) to minimise the KL divergence between circuit and target distributions.

Expand Down
135 changes: 80 additions & 55 deletions examples/classification.ipynb

Large diffs are not rendered by default.

60 changes: 26 additions & 34 deletions examples/heisenberg_vqe.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 2dc1668

Please sign in to comment.