Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
496e0b0
adjust version
Jun 8, 2024
01358ee
prepare for beta release
Jun 27, 2024
191c819
use patched qtrl for tests
Jun 29, 2024
8b489b6
limit numpy version <2
Jun 29, 2024
5392f6c
update setup with numpy version constraint
Jun 30, 2024
1ce4f3c
Merge commit '5392f6ccf9b32b44cc42d4c14fc84e08539f41ce'
Jul 8, 2024
4f6a5a3
some suggestions
Aug 6, 2024
1b86b14
state2state_rl implementation
LegionAtol Aug 8, 2024
2c6c302
Using QobjEvo with Hc, Hd and controls. Dimension action space variab…
LegionAtol Aug 10, 2024
9730959
added _solver.
LegionAtol Aug 11, 2024
2667b64
unitary evolution implementation
LegionAtol Aug 14, 2024
1943609
docstring added
LegionAtol Aug 18, 2024
13ddba0
added callback to stop training
LegionAtol Aug 20, 2024
f2f1d27
added RL algorithm
LegionAtol Aug 22, 2024
1fd9662
rendering update
LegionAtol Aug 22, 2024
0d2df6f
rendering update
LegionAtol Aug 22, 2024
fadb42e
update docstring
LegionAtol Aug 22, 2024
0c68405
update docstring
LegionAtol Aug 22, 2024
e66da0f
Added shorter_pulses to algorithm_kwargs and changed callback to stop…
LegionAtol Aug 24, 2024
6cee77c
Fixed final state saving
LegionAtol Aug 24, 2024
9d6fa29
small corrections
LegionAtol Aug 25, 2024
318081f
edit configuration files
LegionAtol Aug 26, 2024
5403809
Minor text fixes
LegionAtol Sep 9, 2024
4485f9d
Docstring fixes, use of __time__ parameter instead of shorter_pulses,…
LegionAtol Sep 14, 2024
c3c3adb
Merge pull request #18 from LegionAtol/update-guide-control
flowerthrower Sep 25, 2024
3889a63
added _backup_result to keep track of the result even if the algorith…
LegionAtol Sep 30, 2024
cd61877
get kwarg instead of pop
flowerthrower Oct 1, 2024
a5f0016
Merge pull request #22 from qutip/21-prevent-__time__-kwrd-loss
flowerthrower Oct 1, 2024
ceb1de2
automatically convert to superoperator
flowerthrower Oct 2, 2024
9d6ef32
Merge pull request #23 from qutip/20-autmatically-convert-to-superope…
flowerthrower Oct 2, 2024
8fe527b
back to 'shorter_pulses'
flowerthrower Oct 2, 2024
604b12e
pre-commit formating
flowerthrower Oct 2, 2024
d3ce1de
Merge pull request #19 from LegionAtol/ideas
flowerthrower Oct 4, 2024
c115a98
update changelog
flowerthrower Oct 4, 2024
138e3d8
Merge pull request #24 from qutip:prepare_release
flowerthrower Oct 4, 2024
fba6e25
Bump certifi in /doc in the pip group across 1 directory
dependabot[bot] Oct 29, 2024
2ef2db2
Bump urllib3 in /doc in the pip group across 1 directory
dependabot[bot] Oct 29, 2024
da869f6
Bump requests in /doc in the pip group across 1 directory
dependabot[bot] Oct 29, 2024
ec376e5
corrections in algorithm execution time
LegionAtol Dec 18, 2024
d43efb9
Merge pull request #31 from LegionAtol/rl_update
flowerthrower Jan 9, 2025
9d7f277
Make all JAX and machine learning related dependencies optional
pmenczel Jan 23, 2025
2f6c8a3
Fix minor bug
pmenczel Feb 13, 2025
8cc4e09
Update versions of action tools
pmenczel Feb 13, 2025
f403163
Merge pull request #35 from pmenczel/action-tools
pmenczel Feb 17, 2025
5a97ccc
Merge branch 'qutip:main' into dependency-cleanup
pmenczel Feb 17, 2025
1d2591e
Merge pull request #32 from pmenczel/dependency-cleanup
pmenczel Feb 19, 2025
b0fd00c
add check for operator input
rochisha0 Feb 26, 2025
37de33f
Fix objective for open system
rochisha0 Mar 10, 2025
e2781bc
add logic for gate synthesis
rochisha0 Mar 12, 2025
aec775f
Fixing README.md
jyotiraj-code Mar 14, 2025
02d361a
improve the clarity of the code
rochisha0 Mar 18, 2025
029d854
Updated link QuTiP contribution link
jyotiraj-code Mar 18, 2025
95252b2
Merge pull request #39 from jyotiraj-code/main
pmenczel Mar 19, 2025
ae447b6
fix trace
rochisha0 Mar 27, 2025
7981bb5
Merge pull request #36 from rochisha0/state-transfer
pmenczel Mar 28, 2025
5224a21
documentation fix
Akhils777 May 5, 2025
1536669
Merge pull request #28 from qutip/dependabot/pip/doc/pip-775dd686c6
hodgestar May 15, 2025
d91ff67
Merge pull request #27 from qutip/dependabot/pip/doc/pip-a8b23622d7
hodgestar May 15, 2025
6df2f62
Merge pull request #26 from qutip/dependabot/pip/doc/pip-f8e74f74f3
hodgestar May 15, 2025
9a1875c
Bump idna from 2.10 to 3.7 in /doc in the pip group across 1 directory
dependabot[bot] May 15, 2025
35fe0d9
Merge pull request #25 from qutip/dependabot/pip/doc/pip-a98e789dc2
hodgestar May 15, 2025
5402fb0
Bump jinja2 in /doc in the pip group across 1 directory
dependabot[bot] May 15, 2025
4feeea5
Merge pull request #45 from qutip/dependabot/pip/doc/pip-23b04c1fc7
ajgpitch May 16, 2025
ab2f132
Merge pull request #42 from Akhils777/fix-documentation
ajgpitch Jun 5, 2025
d5ff028
Fix: Enable JOPT to support open-system optimization with TRACEDIFF f…
Akhils777 Jul 2, 2025
ee0381f
Match grape infidelity with manually computed one (#51)
rochisha0 Aug 15, 2025
7fe9ce6
Add interactive test notebooks for closed systems (#43)
SeitherJulian Aug 15, 2025
bc385c2
Added requirements for interactive tests to setup.cfg
pmenczel Aug 21, 2025
3fa35c8
Merge pull request #53 from pmenczel/test-requirements
nwlambert Aug 25, 2025
896fcc8
Add file with family package info
veronikakurth Mar 5, 2026
ca2bc1b
Add entry points for family packages to setup.cfg
veronikakurth Mar 6, 2026
8adeb03
Merge pull request #56 from veronikakurth/family_package
pmenczel Mar 6, 2026
30ce20c
Fix merge conflicts appearing when merging main -> qutip-qoc-0.1.X
veronikakurth Mar 10, 2026
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
4 changes: 2 additions & 2 deletions .github/workflows/build_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
name: Install Python
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
# -T : display a full traceback if a Python exception occurs

- name: Upload built files
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: qutip_qoc_html_docs
path: doc/_build/html/*
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
python-version: "3.12"

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ To install the package, use
pip install qutip-qoc
```

By default, the dependencies required for JOPT and for the RL (reinforcement learning) algorithm are omitted.
They can be included by using the targets `qutip-qoc[jopt]` and `qutip-qoc[rl]`, respectively (or `qutip-qoc[full]` for all dependencies).

## Documentation and tutorials

The documentation of `qutip-qoc` updated to the latest development version is hosted at [qutip-qoc.readthedocs.io](https://qutip-qoc.readthedocs.io/en/latest/).
The documentation of `qutip-qoc` updated to the latest development version is hosted at [qutip-qoc.readthedocs.io](https://qutip-qoc.readthedocs.io/latest/).
Tutorials related to using quantum optimal control in `qutip-qoc` can be found [_here_](https://qutip.org/qutip-tutorials/#optimal-control).

## Installation from source
Expand All @@ -40,7 +43,7 @@ pip install --upgrade pip
pip install -e .
```

which makes sure that you are up to date with the latest `pip` version. Contribution guidelines are available [_here_](https://qutip-qoc.readthedocs.io/en/latest/contribution-code.html).
which makes sure that you are up to date with the latest `pip` version. Contribution guidelines are available [_here_](https://qutip-qoc.readthedocs.io/latest/contribution/code.html).

To build and test the documentation, additional packages need to be installed:

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.1
0.1.2
5 changes: 5 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ This is an update to the beta release of ``qutip-qoc``.

It mainly introduces the new reinforcement learning algorithm ``qutip_qoc._rl``.

- Non-public facing functions have been renamed to start with an underscore.
- As with other QuTiP functions, ``optimize_pulses`` now takes a ``tlist`` argument instead of ``_TimeInterval``.
- The structure for the control guess and bounds has changed and now takes in an optional ``__time__`` keyword.
- The ``result`` does no longer return ``optimized_objectives`` but instead ``optimized_H``.

Features
--------

Expand Down
4 changes: 4 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def qutip_qoc_version():

html_theme = "sphinx_rtd_theme"
html_static_path = []
html_js_files = [
'https://code.jquery.com/jquery-3.6.0.min.js',
]


# -- Options for numpydoc ---------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion doc/contribution/code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Contributing to the source code
Build up an development environment
===================================

Please follow the instruction on the `QuTiP contribution guide <https://qutip.org/docs/latest/development/contributing.html#building>`_ to
Please follow the instruction on the `QuTiP contribution guide <https://qutip.readthedocs.io/en/latest/development/contributing.html>`_ to
build a conda environment.

You don't need to build ``qutip`` in the editable mode unless you also want to contribute to `qutip`.
Expand Down
14 changes: 13 additions & 1 deletion doc/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@ In particular, the following packages are necessary for running ``qutip-qoc``:

.. code-block:: bash

numpy scipy jax jaxlib cython qutip qutip-jax qutip-qtrl
numpy scipy cython qutip qutip-qtrl

The following packages are required for using the JOPT algorithm:

.. code-block:: bash

jax jaxlib qutip-jax

The following packages are required for the RL (reinforcement learning) algorithm:

.. code-block:: bash

gymnasium stable-baselines3

The following package is used for testing:

Expand Down
10 changes: 5 additions & 5 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ matplotlib>=3.6.1
docutils==0.18.1
alabaster==0.7.12
Babel==2.9.1
certifi==2020.12.5
certifi==2024.7.4
chardet==4.0.0
colorama==0.4.4
idna==2.10
idna==3.7
imagesize==1.4.1
Jinja2==3.0.1
Jinja2==3.1.6
MarkupSafe==2.0.1
packaging==23.2
Pygments==2.17.2
pyparsing==2.4.7
pytz==2021.1
requests==2.25.1
requests==2.32.2
snowballstemmer==2.1.0
Sphinx==6.1.3
sphinx-gallery==0.12.2
Expand All @@ -32,4 +32,4 @@ sphinxcontrib-htmlhelp==2.0.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
urllib3==1.26.4
urllib3==1.26.19
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cython>=1.0
numpy>=1.16.6,<2.0
scipy>=1.10.1
jax==0.4.28
jaxlib==0.4.28
qutip>=5.0.1
qutip-qtrl
qutip-jax
pre-commit
gymnasium>=0.29.1
stable-baselines3>=2.3.2
21 changes: 16 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,35 @@ package_dir=
packages = find:
include_package_data = True
install_requires =
jax
jaxlib
packaging
qutip
qutip-qtrl
qutip-jax
numpy>=1.16.6,<2.0
gymnasium>=0.29.1
stable-baselines3>=2.3.2
setup_requires =
cython>=1.0
packaging

[options.packages.find]
where = src

[options.entry_points]
qutip.family =
qutip_qoc = qutip_qoc.family

[options.extras_require]
jopt =
jax
jaxlib
qutip-jax
rl =
gymnasium>=0.29.1
stable-baselines3>=2.3.2
tests =
pytest>=6.0
jupytext
nbconvert
ipykernel
full =
%(jopt)s
%(rl)s
%(tests)s
65 changes: 39 additions & 26 deletions src/qutip_qoc/_jopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,47 @@
import qutip as qt
from qutip import Qobj, QobjEvo

from diffrax import Dopri5, PIDController
try:
import jax
from jax import custom_jvp
import jax.numpy as jnp
import qutip_jax # noqa: F401

import jax
from jax import custom_jvp
import jax.numpy as jnp
import qutip_jax # noqa: F401
import jaxlib # noqa: F401

from diffrax import Dopri5, PIDController

@custom_jvp
def _abs(x):
return jnp.abs(x)
_jax_available = True
except ImportError:
_jax_available = False


def _abs_jvp(primals, tangents):
"""
Custom jvp for absolute value of complex functions
"""
(x,) = primals
(t,) = tangents
if _jax_available:

@custom_jvp
def _abs(x):
return jnp.abs(x)


abs_x = _abs(x)
res = jnp.where(
abs_x == 0,
0.0, # prevent division by zero
jnp.real(jnp.multiply(jnp.conj(x), t)) / abs_x,
)
def _abs_jvp(primals, tangents):
"""
Custom jvp for absolute value of complex functions
"""
(x,) = primals
(t,) = tangents

abs_x = _abs(x)
res = jnp.where(
abs_x == 0,
0.0, # prevent division by zero
jnp.real(jnp.multiply(jnp.conj(x), t)) / abs_x,
)

return abs_x, res
return abs_x, res


# register custom jvp for absolut value of complex functions
_abs.defjvp(_abs_jvp)
# register custom jvp for absolut value of complex functions
_abs.defjvp(_abs_jvp)


class _JOPT:
Expand All @@ -55,6 +64,10 @@ def __init__(
guess_params,
**integrator_kwargs,
):
if not _jax_available:
raise ImportError("The JOPT algorithm requires the modules jax, "
"jaxlib, and qutip_jax to be installed.")

self._Hd = objective.H[0]
self._Hc_lst = objective.H[1:]

Expand Down Expand Up @@ -137,8 +150,8 @@ def _infid(self, params):
if self._fid_type == "TRACEDIFF":
diff = X - self._target
# to prevent if/else in qobj.dag() and qobj.tr()
diff_dag = Qobj(diff.data.adjoint(), dims=diff.dims)
g = 1 / 2 * (diff_dag * diff).data.trace()
diff_dag = diff.dag() # direct access to JAX array, no fallback!
g = 1 / 2 * jnp.trace(diff_dag.data._jxa @ diff.data._jxa)
infid = jnp.real(self._norm_fac * g)
else:
g = self._norm_fac * self._target.overlap(X)
Expand All @@ -147,4 +160,4 @@ def _infid(self, params):
elif self._fid_type == "SU": # f_SU (incl global phase)
infid = 1 - jnp.real(g)

return infid
return infid
26 changes: 13 additions & 13 deletions src/qutip_qoc/_rl.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def create_pulse_func(idx):
self._result = Result(
objectives=objectives,
time_interval=time_interval,
start_local_time=time.localtime(), # initial optimization time
start_local_time=time.time(), # initial optimization time
n_iters=0, # Number of iterations(episodes) until convergence
iter_seconds=[], # list containing the time taken for each iteration(episode) of the optimization
var_time=True, # Whether the optimization was performed with variable time
Expand All @@ -99,7 +99,7 @@ def create_pulse_func(idx):
self._backup_result = Result( # used as a backup in case the algorithm with shorter_pulses does not find an episode with infid<target_infid
objectives=objectives,
time_interval=time_interval,
start_local_time=time.localtime(),
start_local_time=time.time(),
n_iters=0,
iter_seconds=[],
var_time=True,
Expand Down Expand Up @@ -180,7 +180,7 @@ def _save_episode_info(self):
"terminated": self.terminated,
"truncated": self.truncated,
"steps_used": self._current_step,
"elapsed_time": time.mktime(time.localtime()),
"elapsed_time": time.time(),
}
self._episode_info.append(episode_data)

Expand Down Expand Up @@ -256,7 +256,7 @@ def reset(self, seed=None):
time_diff = self._episode_info[-1]["elapsed_time"] - (
self._episode_info[-2]["elapsed_time"]
if len(self._episode_info) > 1
else time.mktime(self._result.start_local_time)
else self._result.start_local_time
)
self._result.iter_seconds.append(time_diff)
self._current_step = 0 # Reset the step counter
Expand All @@ -281,7 +281,7 @@ def _save_result(self):
self._backup_result._final_states = self._result._final_states.copy()
self._backup_result.infidelity = self._result.infidelity

result_obj.end_local_time = time.localtime()
result_obj.end_local_time = time.time()
result_obj.n_iters = len(self._result.iter_seconds)
result_obj.optimized_params = self._actions.copy() + [
self._result.total_seconds
Expand All @@ -296,20 +296,20 @@ def result(self):
"""
if self._use_backup_result:
self._backup_result.start_local_time = time.strftime(
"%Y-%m-%d %H:%M:%S", self._backup_result.start_local_time
) # Convert to a string
"%Y-%m-%d %H:%M:%S", time.localtime(self._backup_result.start_local_time)
)
self._backup_result.end_local_time = time.strftime(
"%Y-%m-%d %H:%M:%S", self._backup_result.end_local_time
) # Convert to a string
"%Y-%m-%d %H:%M:%S", time.localtime(self._backup_result.end_local_time)
)
return self._backup_result
else:
self._save_result()
self._result.start_local_time = time.strftime(
"%Y-%m-%d %H:%M:%S", self._result.start_local_time
) # Convert to a string
"%Y-%m-%d %H:%M:%S", time.localtime(self._result.start_local_time)
)
self._result.end_local_time = time.strftime(
"%Y-%m-%d %H:%M:%S", self._result.end_local_time
) # Convert to a string
"%Y-%m-%d %H:%M:%S", time.localtime(self._result.end_local_time)
)
return self._result

def train(self):
Expand Down
8 changes: 8 additions & 0 deletions src/qutip_qoc/family.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""QuTiP family package entry point."""

from . import __version__


def version():
"""Return information to include in qutip.about()."""
return "qutip-qoc", __version__
Loading
Loading