Skip to content

Commit

Permalink
Implement experimental general get_params_to_statevector
Browse files Browse the repository at this point in the history
* Supports general operations beyond parameterized gate application
* Allows for specification of parameters using dictionaries
* Adds a classical register for storage of intermediate computations
(e.g. mid-circuit-measurements)
* Allows the user to define new gates identified by a string

In addition:
* Introduce unstable experimental API in experimental.py
* Add `./examples/experimental` folder for notebooks using unstable API
* Add `experimental/noise_channel_monte_carlo.ipynb` with example
of simulating noise using Monte-Carlo/quantum trajectories
* Add test_experimental.py for testing unstable API
* Add `ParameterizedGateFunction`, `UnparameterizedGateFunction` types
  • Loading branch information
gamatos committed Jan 10, 2024
1 parent f0adb76 commit 5678187
Show file tree
Hide file tree
Showing 18 changed files with 1,184 additions and 9 deletions.
4 changes: 4 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Below are some use-case notebooks. These both illustrate the flexibility of quja
- [classification.ipynb](https://github.com/CQCL/qujax/blob/develop/examples/classification.ipynb) - train a quantum circuit for binary classification using data re-uploading.
- [generative_modelling.ipynb](https://github.com/CQCL/qujax/blob/develop/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.

Experimental (i.e. uses an unstable API which might change in future versions):

- [noise_channel_monte_carlo.ipynb](https://github.com/CQCL/qujax/blob/develop/examples/experimental/noise_channel_monte_carlo.ipynb) - statevector simulation of circuit noise using the Monte-Carlo/quantum trajectories approach.

The [pytket](https://github.com/CQCL/pytket) repository also contains `tk_to_qujax` implementations for some of the above at [pytket-qujax_classification.ipynb](https://github.com/CQCL/pytket/blob/main/examples/pytket-qujax-classification.ipynb),
[pytket-qujax_heisenberg_vqe.ipynb](https://github.com/CQCL/pytket/blob/main/examples/pytket-qujax_heisenberg_vqe.ipynb)
and [pytket-qujax_qaoa.ipynb](https://github.com/CQCL/pytket/blob/main/examples/pytket-qujax_qaoa.ipynb).
8 changes: 8 additions & 0 deletions docs/experimental.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Experimental
=======================

.. toctree::
:titlesonly:

Pure state simulation <experimental/statetensor>

13 changes: 13 additions & 0 deletions docs/experimental/statetensor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Pure state simulation
=======================

.. toctree::
:titlesonly:

statetensor/get_default_gates
statetensor/get_default_operations
statetensor/get_params_to_statetensor_func
statetensor/get_params
statetensor/parse_op
statetensor/wrap_parameterised_tensor

4 changes: 4 additions & 0 deletions docs/experimental/statetensor/get_default_gates.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
get_default_gates
==============================================

.. autofunction:: qujax.experimental.statetensor.get_default_gates
4 changes: 4 additions & 0 deletions docs/experimental/statetensor/get_default_operations.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
get_default_operations
==============================================

.. autofunction:: qujax.experimental.statetensor.get_default_operations
4 changes: 4 additions & 0 deletions docs/experimental/statetensor/get_params.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
get_params
==============================================

.. autofunction:: qujax.experimental.statetensor.get_params
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
get_params_to_statetensor_func
=====================================

.. autofunction:: qujax.experimental.statetensor.get_params_to_statetensor_func
4 changes: 4 additions & 0 deletions docs/experimental/statetensor/parse_op.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parse_op
==============================================

.. autofunction:: qujax.experimental.statetensor.parse_op
4 changes: 4 additions & 0 deletions docs/experimental/statetensor/wrap_parameterised_tensor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
wrap_parameterised_tensor
==============================================

.. autofunction:: qujax.experimental.statetensor.wrap_parameterised_tensor
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Contents
Pure state simulation <statetensor>
Mixed state simulation <densitytensor>
Utility functions <utils>
Experimental <experimental>

.. toctree::
:caption: Links:
Expand Down
2 changes: 1 addition & 1 deletion docs/statetensor/apply_gate.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apply_gate
==============================================

.. autofunction:: qujax.apply_gate
.. autofunction:: qujax.experimental.statetensor.apply_gate
628 changes: 628 additions & 0 deletions examples/experimental/noise_channel_monte_carlo.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions qujax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

import qujax.typing

import qujax.experimental.statetensor

# pylint: disable=undefined-variable
del version
del statetensor
Expand Down
4 changes: 2 additions & 2 deletions qujax/densitytensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from qujax.typing import (
MixedCircuitFunction,
KrausOp,
GateFunction,
ParameterizedGateFunction,
GateParameterIndices,
)

Expand Down Expand Up @@ -86,7 +86,7 @@ def kraus(
def _to_kraus_operator_seq_funcs(
kraus_op: KrausOp,
param_inds: Optional[Union[GateParameterIndices, Sequence[GateParameterIndices]]],
) -> Tuple[Sequence[GateFunction], Sequence[jax.Array]]:
) -> Tuple[Sequence[ParameterizedGateFunction], Sequence[jax.Array]]:
"""
Ensures Kraus operators are a sequence of functions that map (possibly empty) parameters to
tensors and that each element of param_inds_seq is a sequence of arrays that correspond to the
Expand Down
Loading

0 comments on commit 5678187

Please sign in to comment.