From cd618771614787538b50c9bb9c552086866594ce Mon Sep 17 00:00:00 2001 From: flowerthrower Date: Tue, 1 Oct 2024 17:19:22 +0200 Subject: [PATCH] get kwarg instead of pop --- src/qutip_qoc/_goat.py | 4 +++- src/qutip_qoc/_optimizer.py | 3 --- src/qutip_qoc/pulse_optim.py | 7 ++++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qutip_qoc/_goat.py b/src/qutip_qoc/_goat.py index 007388c..617e660 100644 --- a/src/qutip_qoc/_goat.py +++ b/src/qutip_qoc/_goat.py @@ -65,7 +65,9 @@ def __init__( self._var_t = "guess" in time_options # num of params for each control function - self._para_counts = [len(v["guess"]) for v in control_parameters.values()] + self._para_counts = [ + len(v["guess"]) for k, v in control_parameters.items() if k != "__time__" + ] # inferred attributes self._tot_n_para = sum(self._para_counts) # excl. time diff --git a/src/qutip_qoc/_optimizer.py b/src/qutip_qoc/_optimizer.py index e5b12f5..8218d51 100644 --- a/src/qutip_qoc/_optimizer.py +++ b/src/qutip_qoc/_optimizer.py @@ -283,9 +283,6 @@ def _global_local_optimization( _get_init_and_bounds_from_options(x0, control_parameters[key].get("guess")) _get_init_and_bounds_from_options(bounds, control_parameters[key].get("bounds")) - _get_init_and_bounds_from_options(x0, time_options.get("guess", None)) - _get_init_and_bounds_from_options(bounds, time_options.get("bounds", None)) - optimizer_kwargs["x0"] = np.concatenate(x0) multi_objective = _MultiObjective( diff --git a/src/qutip_qoc/pulse_optim.py b/src/qutip_qoc/pulse_optim.py index 45866be..6b2c7f8 100644 --- a/src/qutip_qoc/pulse_optim.py +++ b/src/qutip_qoc/pulse_optim.py @@ -133,7 +133,7 @@ def optimize_pulses( # create time interval time_interval = _TimeInterval(tslots=tlist) - time_options = control_parameters.pop("__time__", {}) + time_options = control_parameters.get("__time__", {}) if time_options: # convert to list of bounds if not already if not isinstance(time_options["bounds"][0], (list, tuple)): time_options["bounds"] = [time_options["bounds"]] @@ -151,8 +151,9 @@ def optimize_pulses( # extract guess and bounds for the control pulses x0, bounds = [], [] for key in control_parameters.keys(): - x0.append(control_parameters[key].get("guess")) - bounds.append(control_parameters[key].get("bounds")) + if key != "__time__": + x0.append(control_parameters[key].get("guess")) + bounds.append(control_parameters[key].get("bounds")) try: # GRAPE, CRAB format lbound = [b[0][0] for b in bounds] ubound = [b[0][1] for b in bounds]