Skip to content

Instantly share code, notes, and snippets.

@ntezak
Created March 17, 2016 20:09
Show Gist options
  • Save ntezak/527cef050697e25c0f1f to your computer and use it in GitHub Desktop.
Save ntezak/527cef050697e25c0f1f to your computer and use it in GitHub Desktop.
def time_dependent_to_qutip(operator, full_space=None, t=symbols("t", real=True)):
import re
if t in operator.all_symbols():
operator = operator.expand()
if isinstance(operator, OperatorPlus):
return [time_dependent_to_qutip(o, full_space) for o in operator.operands]
elif isinstance(operator, ScalarTimesOperator):
return [operator.term.to_qutip(full_space),
re.sub("I", "(1.0j)", str(operator.coeff))] # a bit of a hack to replace imaginary unit
return [operator.to_qutip(full_space), "1"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment