Skip to content
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

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft

Bosonic Fitting #72

wants to merge 14 commits into from

Conversation

gsuarezr
Copy link

@gsuarezr gsuarezr commented Nov 9, 2023

This PR updates the HEOM tutorials according to the corresponding PR on the qutip master branch

Copy link
Member

@pmenczel pmenczel left a 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.

tutorials-v5/heom/heom-1a-spin-bath-model-basic.md Outdated Show resolved Hide resolved
tutorials-v5/heom/heom-1a-spin-bath-model-basic.md Outdated Show resolved Hide resolved
Comment on lines 73 to 76

## 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: delete

Copy link
Member

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

tutorials-v5/heom/heom-1d-spin-bath-model-ohmic-fitting.md Outdated Show resolved Hide resolved
@pmenczel
Copy link
Member

It seems that you have added some ipynb files instead of editing the md files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants