Skip to content

Instantly share code, notes, and snippets.

@SamWolski
Created August 10, 2022 18:01
Show Gist options
  • Save SamWolski/44944b54df6b03e94d95e8f39bb0487e to your computer and use it in GitHub Desktop.
Save SamWolski/44944b54df6b03e94d95e8f39bb0487e to your computer and use it in GitHub Desktop.
Qutip 4 feedback solver
## From https://github.com/qutip/qutip/issues/1571#issuecomment-859873615
times = [0, ...]
# Liouvillians for parts you have control over
control_liouvillians = [qutip.liouvillian(h) for h in control_hamiltonians]
# The time-dependent Hamiltonian for stuff you're not controlling
base_hamiltonian = qutip.QobjEvo([H0, [H1, time_dependence], ...])
# Turn it into a Liouvillian once, so we don't repeat the cost
base = qutip.liouvillian(base_hamiltonian, collapse_operators)
state = ...
options = qutip.Options(store_states=False, store_final_state=True)
for prev, time in zip(times[:-1], times[1:]):
controls = krotov.get_next_controls(time, state, ...)
current_liouvillian = base.copy()
for control, operator in zip(controls, control_liouvillians):
current_liouvillian += control * operator
# ^^^^^^^^^^^^^^^^^^
# each of these terms is a single time-independent Qobj,
# and the sum is a single QobjEvo with all the uncontrolled
# time dependence already handled.
state = qutip.mesolve(current_liouvillian, state, [prev, time], options=options).final_state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment