-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bosonic Fitting #72
base: main
Are you sure you want to change the base?
Bosonic Fitting #72
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall it's nice to see that the new fitting functionality makes everything here much simpler! I went through the changes and had a few questions, see the comments below. I'm not making any comments on the main part of the fitting code yet since I expect that the qutip interface will still change a lot.
|
||
## Helper functions | ||
|
||
Let's define some helper functions for plotting results and timing how long operations take: | ||
|
||
```{code-cell} ipython3 | ||
def coth(x): | ||
""" Vectorized hyperbolic cotangent of x. """ | ||
return 1. / np.tanh(x) | ||
``` | ||
|
||
```{code-cell} ipython3 | ||
def plot_result_expectations(plots, axes=None): | ||
""" Plot the expectation values of operators as functions of time. | ||
|
||
Each plot in plots consists of (solver_result, | ||
measurement_operation, color, label). | ||
""" | ||
if axes is None: | ||
fig, axes = plt.subplots(1, 1, sharex=True, figsize=(8, 8)) | ||
fig_created = True | ||
else: | ||
fig = None | ||
fig_created = False | ||
|
||
# add kw arguments to each plot if missing | ||
plots = [p if len(p) == 5 else p + ({},) for p in plots] | ||
for result, m_op, color, label, kw in plots: | ||
exp = np.real(expect(result.states, m_op)) | ||
kw.setdefault("linewidth", 2) | ||
if color == 'rand': | ||
axes.plot( | ||
result.times, exp, | ||
c=np.random.rand(3,), label=label, **kw, | ||
) | ||
else: | ||
axes.plot(result.times, exp, color, label=label, **kw) | ||
|
||
if fig_created: | ||
axes.legend(loc=0, fontsize=12) | ||
axes.set_xlabel("t", fontsize=28) | ||
|
||
return fig | ||
``` | ||
|
||
```{code-cell} ipython3 | ||
@contextlib.contextmanager | ||
def timer(label): | ||
""" Simple utility for timing functions: | ||
|
||
with timer("name"): | ||
... code to time ... | ||
""" | ||
start = time.time() | ||
yield | ||
end = time.time() | ||
print(f"{label}: {end - start}") | ||
``` | ||
Let's define some helper functions for plotting the resutls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: delete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Github is formatting this weirdly, I meant to delete lines 73-76 since there are no helper functions anymore
Co-authored-by: Paul <[email protected]>
It seems that you have added some |
This PR updates the HEOM tutorials according to the corresponding PR on the qutip master branch