-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tutorial harmonic oscillator configuration space (#11)
* harmonic oscillator model * simple harmonic oscillator * simple harmonic oscillator tests * remove placeholders * ignore .vscode * mkdocs string * add more generic ho * add more generic ho docstring * remove unused imports * add tests for underdamped * add tests for overdamped * add tests for criticaldamped * add tutorials * add tutorials and format * remove hook * rename tutorial harmonic oscillators * rename tutorial harmonic oscillators .py file * rename tutorial harmonic oscillators .py file * add back metadata for tutorial py for mkdocs * switch to plotly * sync jupyter notebooks
- Loading branch information
1 parent
b60fe4c
commit 28c8bc0
Showing
10 changed files
with
1,851 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,3 +160,4 @@ cython_debug/ | |
#.idea/ | ||
|
||
.vscode | ||
*.ipynb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# --- | ||
# jupyter: | ||
# jupytext: | ||
# formats: ipynb,py:percent | ||
# text_representation: | ||
# extension: .py | ||
# format_name: percent | ||
# format_version: '1.3' | ||
# jupytext_version: 1.16.1 | ||
# kernelspec: | ||
# display_name: .venv | ||
# language: python | ||
# name: python3 | ||
# --- | ||
|
||
# %% [markdown] | ||
# # Harmonic Oscillators | ||
# | ||
# In this tutorial, we demo how to generate data of harmonic oscillators. | ||
|
||
# %% | ||
import pandas as pd | ||
import plotly.express as px | ||
|
||
from hamiltonian_flow.models.harmonic_oscillator import HarmonicOscillator | ||
|
||
# %% | ||
n_periods = 3 | ||
n_samples_per_period = 200 | ||
|
||
# %% [markdown] | ||
# ## Simple Harmonic Oscillator | ||
|
||
# %% | ||
sho_omega = 0.5 | ||
|
||
sho = HarmonicOscillator(system={"omega": sho_omega}) | ||
|
||
# %% | ||
df_sho = sho(n_periods=n_periods, n_samples_per_period=n_samples_per_period) | ||
df_sho.head() | ||
|
||
# %% | ||
px.line( | ||
df_sho, | ||
x="t", | ||
y="x", | ||
title=rf"Simple Harmonic Oscillator (omega = {sho_omega})", | ||
labels={ | ||
"x": r"Displacement $x(t)$", | ||
"t": r"$t$", | ||
}, | ||
) | ||
|
||
# %% [markdown] | ||
# ## Damped Harmonic Oscillator | ||
|
||
# %% | ||
dho_systems = { | ||
"Underdamped": {"omega": 0.5, "zeta": 0.2}, | ||
"Critical Damped": {"omega": 0.5, "zeta": 1}, | ||
"Overdamped": { | ||
"omega": 0.5, | ||
"zeta": 1.2, | ||
}, | ||
} | ||
|
||
dfs_dho = [] | ||
|
||
for s_name, s in dho_systems.items(): | ||
|
||
dfs_dho.append( | ||
HarmonicOscillator(system=s)( | ||
n_periods=n_periods, n_samples_per_period=n_samples_per_period | ||
).assign(system=rf"{s_name} (omega = {s.get('omega')}, zeta = {s.get('zeta')})") | ||
) | ||
|
||
fig = px.line( | ||
pd.concat(dfs_dho), | ||
x="t", | ||
y="x", | ||
color="system", | ||
title=rf"Damped Harmonic Oscillator", | ||
labels={ | ||
"x": r"Displacement $x(t)$", | ||
"t": r"$t$", | ||
}, | ||
) | ||
fig.update_layout(legend={"yanchor": "top", "y": -0.2, "xanchor": "left", "x": 0}) | ||
|
||
# %% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# Tutorials | ||
|
||
We provide some tutorials to help you get started. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.