Skip to content

Commit

Permalink
doc(model): #71 add a tutorial for the complex oscillator (#72)
Browse files Browse the repository at this point in the history
* fix(typing): #69

* doc(model): #71 tutorial for the complex oscillator

* chore(poetry): #71 docs versions

* chore(cd): #71 fix NameError: name 'system_specs' is not defined

* fix(comment): #71 @emptymalei #72 (review)
  • Loading branch information
cmp0xff authored Jul 29, 2024
1 parent 91b5db9 commit 04ea13c
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/tutorials/brownian_motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.16.3
# jupytext_version: 1.16.4
# kernelspec:
# display_name: .venv
# language: python
Expand Down
78 changes: 78 additions & 0 deletions docs/tutorials/complex_harmonic_oscillator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# ---
# jupyter:
# jupytext:
# formats: ipynb,py:percent
# text_representation:
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.16.4
# kernelspec:
# display_name: .venv
# language: python
# name: python3
# ---

# %% [markdown]
# # Complex Harmonic Oscillator
#
# In this tutorial, we show a few interesting examples of the complex simple harmonic oscillator.

# %%
import math

import numpy as np
from plotly import express as px

from hamilflow.models.harmonic_oscillator import ComplexSimpleHarmonicOscillator

# %% [markdown]
# ## Basic setups

# %%
t = np.linspace(0, 3, 257)
system_specs = dict(omega=2 * math.pi)

# %% [markdown]
# ## Positive-frequency, circular-polarised mode
# Also known as the left-rotating mode.

# %%
csho = ComplexSimpleHarmonicOscillator(system_specs, initial_condition=dict(x0=(1, 0)))

df = csho(t)

arr_z = df["z"].to_numpy(copy=False)

px.line_3d(x=arr_z.real, y=arr_z.imag, z=t, labels=dict(x="real", y="imag", z="time"))

# %% [markdown]
# ## Negative-frequency, circular-polarised mode
# Also known as the right-rotating mode.

# %%
csho = ComplexSimpleHarmonicOscillator(system_specs, initial_condition=dict(x0=(0, 1)))

df = csho(t)

arr_z = df["z"].to_numpy(copy=False)

px.line_3d(x=arr_z.real, y=arr_z.imag, z=t, labels=dict(x="real", y="imag", z="time"))

# %% [markdown]
# ## Positive-frequency, elliptic-polarised mode

# %%
csho = ComplexSimpleHarmonicOscillator(
system_specs,
initial_condition=dict(x0=(math.cos(math.pi / 12), math.sin(math.pi / 12))),
)

df = csho(t)

arr_z = df["z"].to_numpy(copy=False)

px.line_3d(x=arr_z.real, y=arr_z.imag, z=t, labels=dict(x="real", y="imag", z="time"))

# %% [markdown]
# # End of Notebook
2 changes: 1 addition & 1 deletion docs/tutorials/harmonic_oscillator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.16.1
# jupytext_version: 1.16.4
# kernelspec:
# display_name: .venv
# language: python
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/pendulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.16.1
# jupytext_version: 1.16.4
# kernelspec:
# display_name: .venv
# language: python
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ nav:
- "Tutorials":
- "Introduction": tutorials/index.md
- "Harmonic Oscillator": tutorials/harmonic_oscillator.py
- "Complex Harmonic Oscillator": tutorials/complex_harmonic_oscillator.py
- "Brownian Motion": tutorials/brownian_motion.py
- "Pendulum": tutorials/pendulum.py
- References:
Expand Down
21 changes: 11 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ pytest-cov = "^4.1.0"


[tool.poetry.group.docs.dependencies]
mkdocs-material = "^9.5.9"
mkdocs-autorefs = "^0.5.0"
mkdocstrings = {version = "^0.24.0", extras = ["python"]}
mkdocs-jupyter = "^0.24.6"

mkdocs-material = "^9.5.30"
mkdocs-autorefs = "^1.0.1"
mkdocstrings = {version = "^0.25.2", extras = ["python"]}
mkdocs-jupyter = "^0.24.8"


[tool.poetry.group.tutorial.dependencies]
Expand Down

0 comments on commit 04ea13c

Please sign in to comment.