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

Add precommit.yaml file #72

Merged
merged 15 commits into from
Aug 12, 2024
Merged
31 changes: 31 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
exclude: 'dev'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-merge-conflict # checks for files that contain merge conflict strings
- id: check-toml # checks toml files for parseable syntax
- id: debug-statements # checks for debugger imports and py37+ `breakpoint()` calls in python source

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.2
hooks:
# Run the linter.
- id: ruff
types_or: [python, pyi, jupyter]
args:
- --fix
- --exit-non-zero-on-fix
- --per-file-ignores
- getting-started/python-basics.ipynb:E999

# Run the formatter.
- id: ruff-format
types_or: [python, pyi, jupyter]
exclude: getting-started/python-basics.ipynb

# - repo: https://github.com/codespell-project/codespell
# rev: v2.1.0
# hooks:
# - id: codespell
39,258 changes: 18,680 additions & 20,578 deletions demo.ipynb

Large diffs are not rendered by default.

188 changes: 115 additions & 73 deletions examples/07-tutorial-standard-problem3.ipynb

Large diffs are not rendered by default.

29 changes: 16 additions & 13 deletions examples/08-tutorial-standard-problem4.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"metadata": {},
"outputs": [],
"source": [
"system = mm.System(name='stdprob4')"
"system = mm.System(name=\"stdprob4\")"
]
},
{
Expand Down Expand Up @@ -299,7 +299,7 @@
],
"source": [
"# x-component\n",
"system.m.x.sel('z').mpl()"
"system.m.x.sel(\"z\").mpl()"
]
},
{
Expand All @@ -320,7 +320,7 @@
],
"source": [
"# y-component\n",
"system.m.y.sel('z').mpl()"
"system.m.y.sel(\"z\").mpl()"
]
},
{
Expand All @@ -341,7 +341,7 @@
],
"source": [
"# vectors\n",
"system.m.sel('z').mpl()"
"system.m.sel(\"z\").mpl()"
]
},
{
Expand Down Expand Up @@ -375,10 +375,10 @@
"fig, ax = plt.subplots(figsize=(20, 5))\n",
"\n",
"# plot vectors on grid of 20 x 5 over the numerical resulotion\n",
"system.m.sel('z').resample((20, 5)).mpl.vector(ax=ax)\n",
"system.m.sel(\"z\").resample((20, 5)).mpl.vector(ax=ax)\n",
"\n",
"# add colouring for mx-component to this plot\n",
"system.m.x.sel('z').mpl.scalar(ax=ax, cmap='magma')"
"system.m.x.sel(\"z\").mpl.scalar(ax=ax, cmap=\"magma\")"
]
},
{
Expand Down Expand Up @@ -408,10 +408,13 @@
}
],
"source": [
"print('The average magnetisation is {}.'.format(system.m.mean()))\n",
"print(\"The average magnetisation is {}.\".format(system.m.mean()))\n",
"\n",
"print('The magnetisation at the mesh centre {}\\nis {}.'.format(\n",
" system.m.mesh.region.centre, system.m(system.m.mesh.region.centre)))"
"print(\n",
" \"The magnetisation at the mesh centre {}\\nis {}.\".format(\n",
" system.m.mesh.region.centre, system.m(system.m.mesh.region.centre)\n",
" )\n",
")"
]
},
{
Expand All @@ -435,7 +438,7 @@
"outputs": [],
"source": [
"# Add Zeeman energy term to the Hamiltonian\n",
"H1 = (-24.6e-3/mm.consts.mu0, 4.3e-3/mm.consts.mu0, 0.0)\n",
"H1 = (-24.6e-3 / mm.consts.mu0, 4.3e-3 / mm.consts.mu0, 0.0)\n",
"system.energy += mm.Zeeman(H=H1)"
]
},
Expand Down Expand Up @@ -749,7 +752,7 @@
}
],
"source": [
"myplot = system.table.data.plot('t', 'my')"
"myplot = system.table.data.plot(\"t\", \"my\")"
]
},
{
Expand Down Expand Up @@ -783,10 +786,10 @@
"fig, ax = plt.subplots(figsize=(20, 5))\n",
"\n",
"# plot vectors on grid of 20 x 5 over the numerical resulotion\n",
"system.m.sel('z').resample((20, 5)).mpl.vector(ax=ax)\n",
"system.m.sel(\"z\").resample((20, 5)).mpl.vector(ax=ax)\n",
"\n",
"# add colouring for mx-component to this plot\n",
"system.m.x.sel('z').mpl.scalar(ax=ax, cmap='magma')"
"system.m.x.sel(\"z\").mpl.scalar(ax=ax, cmap=\"magma\")"
]
},
{
Expand Down
19 changes: 11 additions & 8 deletions examples/09-tutorial-standard-problem5.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
"metadata": {},
"outputs": [],
"source": [
"import oommfc as oc\n",
"import discretisedfield as df\n",
"import micromagneticmodel as mm"
"import micromagneticmodel as mm\n",
"import oommfc as oc"
]
},
{
Expand All @@ -64,7 +64,7 @@
"lx = 100e-9 # x dimension of the sample(m)\n",
"ly = 100e-9 # y dimension of the sample (m)\n",
"lz = 10e-9 # sample thickness (m)\n",
"dx = dy = dz = 5e-9 #discretisation cell (nm)\n",
"dx = dy = dz = 5e-9 # discretisation cell (nm)\n",
"\n",
"# Material (permalloy) parameters\n",
"Ms = 8e5 # saturation magnetisation (A/m)\n",
Expand All @@ -90,7 +90,7 @@
"metadata": {},
"outputs": [],
"source": [
"system = mm.System(name='stdprob5')"
"system = mm.System(name=\"stdprob5\")"
]
},
{
Expand Down Expand Up @@ -182,10 +182,11 @@
],
"source": [
"def m_vortex(pos):\n",
" x, y, z = pos[0]/1e-9-50, pos[1]/1e-9-50, pos[2]/1e-9\n",
" \n",
" x, y, _ = pos[0] / 1e-9 - 50, pos[1] / 1e-9 - 50, pos[2] / 1e-9\n",
"\n",
" return (-y, x, 10)\n",
"\n",
"\n",
"system.m = df.Field(mesh, nvdim=3, value=m_vortex, norm=Ms)\n",
"system.m.sel(z=0).mpl()"
]
Expand Down Expand Up @@ -271,7 +272,9 @@
}
],
"source": [
"system.dynamics += mm.Precession(gamma0=gamma0) + mm.Damping(alpha=alpha) + mm.ZhangLi(u=ux, beta=beta)\n",
"system.dynamics += (\n",
" mm.Precession(gamma0=gamma0) + mm.Damping(alpha=alpha) + mm.ZhangLi(u=ux, beta=beta)\n",
")\n",
"system.dynamics"
]
},
Expand Down Expand Up @@ -354,7 +357,7 @@
}
],
"source": [
"system.table.data.plot('t', 'mx')"
"system.table.data.plot(\"t\", \"mx\")"
]
},
{
Expand Down
22 changes: 11 additions & 11 deletions examples/10-tutorial-standard-problem-fmr.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"source": [
"mesh = df.Mesh(p1=(0, 0, 0), p2=(lx, ly, lz), cell=(dx, dy, dz))\n",
"\n",
"system = mm.System(name='stdprobfmr')\n",
"system = mm.System(name=\"stdprobfmr\")\n",
"\n",
"system.energy = mm.Exchange(A=A) + mm.Demag() + mm.Zeeman(H=H)\n",
"system.dynamics = mm.Precession(gamma0=gamma0) + mm.Damping(alpha=alpha)\n",
Expand Down Expand Up @@ -139,7 +139,7 @@
}
],
"source": [
"system.m.sel('z').resample((10, 10)).mpl()"
"system.m.sel(\"z\").resample((10, 10)).mpl()"
]
},
{
Expand Down Expand Up @@ -228,14 +228,14 @@
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"t = system.table.data['t'].values\n",
"my = system.table.data['mx'].values\n",
"t = system.table.data[\"t\"].values\n",
"my = system.table.data[\"mx\"].values\n",
"\n",
"# Plot <my> time evolution.\n",
"plt.figure(figsize=(8, 6))\n",
"plt.plot(t, my)\n",
"plt.xlabel('t (ns)')\n",
"plt.ylabel('my average')\n",
"plt.xlabel(\"t (ns)\")\n",
"plt.ylabel(\"my average\")\n",
"plt.grid()"
]
},
Expand Down Expand Up @@ -265,13 +265,13 @@
"source": [
"import scipy.fft\n",
"\n",
"psd = np.log10(np.abs(scipy.fft.fft(my))**2)\n",
"f_axis = scipy.fft.fftfreq(4000, d=20e-9/4000)\n",
"psd = np.log10(np.abs(scipy.fft.fft(my)) ** 2)\n",
"f_axis = scipy.fft.fftfreq(4000, d=20e-9 / 4000)\n",
"\n",
"plt.plot(f_axis/1e9, psd)\n",
"plt.plot(f_axis / 1e9, psd)\n",
"plt.xlim([6, 12])\n",
"plt.xlabel('f (GHz)')\n",
"plt.ylabel('Psa (a.u.)')\n",
"plt.xlabel(\"f (GHz)\")\n",
"plt.ylabel(\"Psa (a.u.)\")\n",
"plt.grid()"
]
},
Expand Down
21 changes: 10 additions & 11 deletions examples/11-tutorial-deriving-fields.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,15 @@
}
],
"source": [
"system = mm.System(name='system')\n",
"system = mm.System(name=\"system\")\n",
"\n",
"A = 1e-11\n",
"H = (0.1/mm.consts.mu0, 0, 0)\n",
"H = (0.1 / mm.consts.mu0, 0, 0)\n",
"K = 1e3\n",
"u = (1, 1, 1)\n",
"system.energy = (mm.Exchange(A=A)\n",
" + mm.Demag()\n",
" + mm.Zeeman(H=H)\n",
" + mm.UniaxialAnisotropy(K=K, u=u))\n",
"system.energy = (\n",
" mm.Exchange(A=A) + mm.Demag() + mm.Zeeman(H=H) + mm.UniaxialAnisotropy(K=K, u=u)\n",
")\n",
"\n",
"system.energy"
]
Expand Down Expand Up @@ -158,7 +157,7 @@
}
],
"source": [
"oc.compute(system.energy.effective_field, system).sel('x').mpl()"
"oc.compute(system.energy.effective_field, system).sel(\"x\").mpl()"
]
},
{
Expand Down Expand Up @@ -244,7 +243,7 @@
],
"source": [
"w = oc.compute(system.energy.density, system)\n",
"w.sel('x').mpl()"
"w.sel(\"x\").mpl()"
]
},
{
Expand All @@ -270,7 +269,7 @@
],
"source": [
"E = oc.compute(system.energy.energy, system)\n",
"print(f'The energy of the system is {E} J.')"
"print(f\"The energy of the system is {E} J.\")"
]
},
{
Expand Down Expand Up @@ -333,7 +332,7 @@
"E = oc.compute(system.energy.energy, system)\n",
"print(\"The system's energy is {} J.\".format(E))\n",
"\n",
"system.m.sel('x').mpl()"
"system.m.sel(\"x\").mpl()"
]
},
{
Expand Down Expand Up @@ -419,7 +418,7 @@
"total_energy = 0\n",
"for term in system.energy:\n",
" total_energy += oc.compute(term.energy, system)\n",
" \n",
"\n",
"print(\"The sum of energy terms is {} J.\".format(total_energy))\n",
"print(\"The system's energy is {} J.\".format(oc.compute(system.energy.energy, system)))"
]
Expand Down
10 changes: 6 additions & 4 deletions examples/12-tutorial-stray-field.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
"region = df.Region(p1=(-100e-9, -100e-9, -100e-9), p2=(100e-9, 100e-9, 100e-9))\n",
"mesh = df.Mesh(region=region, cell=(5e-9, 5e-9, 5e-9))\n",
"\n",
"\n",
"def norm_fun(pos):\n",
" x, y, z = pos\n",
" if -50e-9 <= x <= 50e-9 and -50e-9 <= y <= 50e-9 and -50e-9 <= z <= 50e-9:\n",
" return 8e5\n",
" else:\n",
" return 0\n",
"\n",
"system = mm.System(name='airbox_method')\n",
"\n",
"system = mm.System(name=\"airbox_method\")\n",
"system.energy = mm.Exchange(A=1e-12) + mm.Demag()\n",
"system.dynamics = mm.Precession(gamma0=mm.consts.gamma0) + mm.Damping(alpha=1)\n",
"system.m = df.Field(mesh, nvdim=3, value=(0, 0, 1), norm=norm_fun, valid=\"norm\")"
Expand Down Expand Up @@ -65,7 +67,7 @@
}
],
"source": [
"system.m.norm.sel('z').mpl()"
"system.m.norm.sel(\"z\").mpl()"
]
},
{
Expand Down Expand Up @@ -102,7 +104,7 @@
"md = oc.MinDriver()\n",
"md.drive(system)\n",
"\n",
"system.m.sel('z').mpl(figsize=(10, 10))"
"system.m.sel(\"z\").mpl(figsize=(10, 10))"
]
},
{
Expand Down Expand Up @@ -159,7 +161,7 @@
}
],
"source": [
"stray_field.sel('z').mpl(figsize=(8, 8), vector_kw={'scale': 1e6})"
"stray_field.sel(\"z\").mpl(figsize=(8, 8), vector_kw={\"scale\": 1e6})"
]
}
],
Expand Down
Loading
Loading