Skip to content
Merged
Changes from all commits
Commits
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
23 changes: 22 additions & 1 deletion src/qutip_qoc/pulse_optim.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,34 +195,55 @@ def optimize_pulses(
"maxiter": algorithm_kwargs.get("max_iter", 1000),
"gtol": algorithm_kwargs.get("min_grad", 0.0 if alg == "CRAB" else 1e-8),
}

# Iterate over objectives and convert initial and target states based on the optimization type
for objective in objectives:
H_list = objective.H if isinstance(objective.H, list) else [objective.H]
if any(qt.issuper(H_i) for H_i in H_list):
if isinstance(optimization_type, str) and optimization_type.lower() == "state_transfer":
if qt.isket(objective.initial):
dim = objective.initial.shape[0]
objective.initial = qt.operator_to_vector(qt.ket2dm(objective.initial))
elif qt.isoper(objective.initial):
dim = objective.initial.shape[0]
objective.initial = qt.operator_to_vector(objective.initial)

if qt.isket(objective.target):
objective.target = qt.operator_to_vector(qt.ket2dm(objective.target))
elif qt.isoper(objective.target):
objective.target = qt.operator_to_vector(objective.target)

algorithm_kwargs.setdefault("fid_params", {})
algorithm_kwargs["fid_params"].setdefault("scale_factor", 1.0 / dim)

elif isinstance(optimization_type, str) and optimization_type.lower() == "gate_synthesis":
objective.initial = qt.to_super(objective.initial)
objective.target = qt.to_super(objective.target)

elif optimization_type is None:
is_state_transfer = False
if qt.isoper(objective.initial) and qt.isoper(objective.target):
if np.isclose((objective.initial).tr(), 1) and np.isclose((objective.target).tr(), 1):
if np.isclose(objective.initial.tr(), 1) and np.isclose(objective.target.tr(), 1):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a strange way to check if something is a density matrix

dim = objective.initial.shape[0]
objective.initial = qt.operator_to_vector(objective.initial)
objective.target = qt.operator_to_vector(objective.target)
is_state_transfer = True
else:
objective.initial = qt.to_super(objective.initial)
objective.target = qt.to_super(objective.target)

if qt.isket(objective.initial):
dim = objective.initial.shape[0]
objective.initial = qt.operator_to_vector(qt.ket2dm(objective.initial))
is_state_transfer = True

if qt.isket(objective.target):
objective.target = qt.operator_to_vector(qt.ket2dm(objective.target))
is_state_transfer = True

if is_state_transfer:
algorithm_kwargs.setdefault("fid_params", {})
algorithm_kwargs["fid_params"].setdefault("scale_factor", 1.0 / dim)

# prepare qtrl optimizers
qtrl_optimizers = []
Expand Down
Loading