-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/flowerthrower/qutip-qoc
- Loading branch information
Showing
36 changed files
with
515 additions
and
2,829 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.0.dev1 | ||
0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
numpy>=1.16.6 | ||
scipy>=1.10.1 | ||
jax>=0.4.23 | ||
jaxlib>=0.4.23 | ||
qutip==4.7.0 | ||
cython==0.29.33 | ||
sphinx==6.1.3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
cython>=1.0 | ||
numpy>=1.16.6 | ||
scipy>=1.10.1 | ||
qutip @ git+https://github.com/qutip/qutip.git@master | ||
jax>=0.4.23 | ||
jaxlib>=0.4.23 | ||
qutip>=5.0.1 | ||
qutip-qtrl @ git+https://github.com/flowerthrower/qutip-qtrl@patrick/parameterize_crab | ||
qutip-jax @ git+https://github.com/qutip/qutip-jax.git@master | ||
qutip-jax | ||
pre-commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ classifiers = | |
Operating System :: POSIX | ||
Operating System :: Unix | ||
Operating System :: Microsoft :: Windows | ||
author = Alexander Pitchford, Paul D. Nation, Robert J. Johansson, Chris Granade, Arne Grimsmo, Nathan Shammah, Shahnawaz Ahmed, Neill Lambert, Eric Giguere, Boxi Li, Jake Lishman | ||
author = Patrick Hopf, Paul Menczel, Alexander Pitchford, Neil Lambert | ||
author_email = [email protected] | ||
platforms = Linux, Mac OSX, Unix, Windows | ||
|
||
|
@@ -28,10 +28,12 @@ package_dir= | |
packages = find: | ||
include_package_data = True | ||
install_requires = | ||
qutip @ git+https://github.com/qutip/qutip.git@master | ||
qutip-qtrl @ git+https://github.com/qutip/qutip-qtrl.git@master | ||
qutip-jax @ git+https://github.com/qutip/qutip-jax.git@master | ||
jax | ||
jaxlib | ||
packaging | ||
qutip | ||
qutip-qtrl @ git+https://github.com/flowerthrower/qutip-qtrl@patrick/parameterize_crab | ||
qutip-jax | ||
setup_requires = | ||
cython>=1.0 | ||
packaging | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
""" | ||
This module provides an interface to the CRAB optimization algorithm in qutip-qtrl. | ||
It defines the _CRAB class, which uses a qutip_qtrl.optimizer.Optimizer object | ||
to store the control problem and calculate the fidelity error function and its gradient | ||
with respect to the control parameters, according to the CRAB algorithm. | ||
""" | ||
|
||
import qutip_qtrl.logging_utils as logging | ||
import copy | ||
|
||
logger = logging.get_logger() | ||
|
||
|
||
class _CRAB: | ||
""" | ||
Class to interface with the CRAB optimization algorithm in qutip-qtrl. | ||
It has an attribute `qtrl` that is a `qutip_qtrl.optimizer.Optimizer` object | ||
for storing the control problem and calculating the fidelity error function | ||
and its gradient wrt the control parameters, according to the CRAB algorithm. | ||
The class does only provide the infidelity method, as the CRAB algorithm is | ||
not a gradient-based optimization. | ||
""" | ||
|
||
def __init__(self, qtrl_optimizer): | ||
self._qtrl = copy.deepcopy(qtrl_optimizer) | ||
self.gradient = None | ||
|
||
def infidelity(self, *args): | ||
""" | ||
This method is adapted from the original | ||
`qutip_qtrl.optimizer.Optimizer.fid_err_func_wrapper` | ||
Get the fidelity error achieved using the ctrl amplitudes passed | ||
in as the first argument. | ||
This is called by generic optimisation algorithm as the | ||
func to the minimised. The argument is the current | ||
variable values, i.e. control amplitudes, passed as | ||
a flat array. Hence these are reshaped as [nTimeslots, n_ctrls] | ||
and then used to update the stored ctrl values (if they have changed) | ||
""" | ||
self._qtrl.num_fid_func_calls += 1 | ||
# *** update stats *** | ||
if self._qtrl.stats is not None: | ||
self._qtrl.stats.num_fidelity_func_calls = self._qtrl.num_fid_func_calls | ||
if self._qtrl.log_level <= logging.DEBUG: | ||
logger.debug( | ||
"fidelity error call {}".format( | ||
self._qtrl.stats.num_fidelity_func_calls | ||
) | ||
) | ||
|
||
amps = self._qtrl._get_ctrl_amps(args[0].copy()) | ||
self._qtrl.dynamics.update_ctrl_amps(amps) | ||
|
||
err = self._qtrl.dynamics.fid_computer.get_fid_err() | ||
|
||
if self._qtrl.iter_summary: | ||
self._qtrl.iter_summary.fid_func_call_num = self._qtrl.num_fid_func_calls | ||
self._qtrl.iter_summary.fid_err = err | ||
|
||
if self._qtrl.dump and self._qtrl.dump.dump_fid_err: | ||
self._qtrl.dump.update_fid_err_log(err) | ||
|
||
return err |
Oops, something went wrong.