Skip to content

Commit 31b454f

Browse files
authored
Merge pull request #72 from ubermag/add_precommit
Add precommit.yaml file
2 parents df1b84c + e1681c9 commit 31b454f

34 files changed

+19778
-22572
lines changed

.pre-commit-config.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
exclude: 'dev'
2+
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.5.0
6+
hooks:
7+
- id: check-merge-conflict # checks for files that contain merge conflict strings
8+
- id: check-toml # checks toml files for parseable syntax
9+
- id: debug-statements # checks for debugger imports and py37+ `breakpoint()` calls in python source
10+
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
rev: v0.4.2
13+
hooks:
14+
# Run the linter.
15+
- id: ruff
16+
types_or: [python, pyi, jupyter]
17+
args:
18+
- --fix
19+
- --exit-non-zero-on-fix
20+
- --per-file-ignores
21+
- getting-started/python-basics.ipynb:E999
22+
23+
# Run the formatter.
24+
- id: ruff-format
25+
types_or: [python, pyi, jupyter]
26+
exclude: getting-started/python-basics.ipynb
27+
28+
# - repo: https://github.com/codespell-project/codespell
29+
# rev: v2.1.0
30+
# hooks:
31+
# - id: codespell

demo.ipynb

Lines changed: 18680 additions & 20578 deletions
Large diffs are not rendered by default.

examples/07-tutorial-standard-problem3.ipynb

Lines changed: 115 additions & 73 deletions
Large diffs are not rendered by default.

examples/08-tutorial-standard-problem4.ipynb

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"metadata": {},
9797
"outputs": [],
9898
"source": [
99-
"system = mm.System(name='stdprob4')"
99+
"system = mm.System(name=\"stdprob4\")"
100100
]
101101
},
102102
{
@@ -299,7 +299,7 @@
299299
],
300300
"source": [
301301
"# x-component\n",
302-
"system.m.x.sel('z').mpl()"
302+
"system.m.x.sel(\"z\").mpl()"
303303
]
304304
},
305305
{
@@ -320,7 +320,7 @@
320320
],
321321
"source": [
322322
"# y-component\n",
323-
"system.m.y.sel('z').mpl()"
323+
"system.m.y.sel(\"z\").mpl()"
324324
]
325325
},
326326
{
@@ -341,7 +341,7 @@
341341
],
342342
"source": [
343343
"# vectors\n",
344-
"system.m.sel('z').mpl()"
344+
"system.m.sel(\"z\").mpl()"
345345
]
346346
},
347347
{
@@ -375,10 +375,10 @@
375375
"fig, ax = plt.subplots(figsize=(20, 5))\n",
376376
"\n",
377377
"# plot vectors on grid of 20 x 5 over the numerical resulotion\n",
378-
"system.m.sel('z').resample((20, 5)).mpl.vector(ax=ax)\n",
378+
"system.m.sel(\"z\").resample((20, 5)).mpl.vector(ax=ax)\n",
379379
"\n",
380380
"# add colouring for mx-component to this plot\n",
381-
"system.m.x.sel('z').mpl.scalar(ax=ax, cmap='magma')"
381+
"system.m.x.sel(\"z\").mpl.scalar(ax=ax, cmap=\"magma\")"
382382
]
383383
},
384384
{
@@ -408,10 +408,13 @@
408408
}
409409
],
410410
"source": [
411-
"print('The average magnetisation is {}.'.format(system.m.mean()))\n",
411+
"print(\"The average magnetisation is {}.\".format(system.m.mean()))\n",
412412
"\n",
413-
"print('The magnetisation at the mesh centre {}\\nis {}.'.format(\n",
414-
" system.m.mesh.region.centre, system.m(system.m.mesh.region.centre)))"
413+
"print(\n",
414+
" \"The magnetisation at the mesh centre {}\\nis {}.\".format(\n",
415+
" system.m.mesh.region.centre, system.m(system.m.mesh.region.centre)\n",
416+
" )\n",
417+
")"
415418
]
416419
},
417420
{
@@ -435,7 +438,7 @@
435438
"outputs": [],
436439
"source": [
437440
"# Add Zeeman energy term to the Hamiltonian\n",
438-
"H1 = (-24.6e-3/mm.consts.mu0, 4.3e-3/mm.consts.mu0, 0.0)\n",
441+
"H1 = (-24.6e-3 / mm.consts.mu0, 4.3e-3 / mm.consts.mu0, 0.0)\n",
439442
"system.energy += mm.Zeeman(H=H1)"
440443
]
441444
},
@@ -749,7 +752,7 @@
749752
}
750753
],
751754
"source": [
752-
"myplot = system.table.data.plot('t', 'my')"
755+
"myplot = system.table.data.plot(\"t\", \"my\")"
753756
]
754757
},
755758
{
@@ -783,10 +786,10 @@
783786
"fig, ax = plt.subplots(figsize=(20, 5))\n",
784787
"\n",
785788
"# plot vectors on grid of 20 x 5 over the numerical resulotion\n",
786-
"system.m.sel('z').resample((20, 5)).mpl.vector(ax=ax)\n",
789+
"system.m.sel(\"z\").resample((20, 5)).mpl.vector(ax=ax)\n",
787790
"\n",
788791
"# add colouring for mx-component to this plot\n",
789-
"system.m.x.sel('z').mpl.scalar(ax=ax, cmap='magma')"
792+
"system.m.x.sel(\"z\").mpl.scalar(ax=ax, cmap=\"magma\")"
790793
]
791794
},
792795
{

examples/09-tutorial-standard-problem5.ipynb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
"metadata": {},
4343
"outputs": [],
4444
"source": [
45-
"import oommfc as oc\n",
4645
"import discretisedfield as df\n",
47-
"import micromagneticmodel as mm"
46+
"import micromagneticmodel as mm\n",
47+
"import oommfc as oc"
4848
]
4949
},
5050
{
@@ -64,7 +64,7 @@
6464
"lx = 100e-9 # x dimension of the sample(m)\n",
6565
"ly = 100e-9 # y dimension of the sample (m)\n",
6666
"lz = 10e-9 # sample thickness (m)\n",
67-
"dx = dy = dz = 5e-9 #discretisation cell (nm)\n",
67+
"dx = dy = dz = 5e-9 # discretisation cell (nm)\n",
6868
"\n",
6969
"# Material (permalloy) parameters\n",
7070
"Ms = 8e5 # saturation magnetisation (A/m)\n",
@@ -90,7 +90,7 @@
9090
"metadata": {},
9191
"outputs": [],
9292
"source": [
93-
"system = mm.System(name='stdprob5')"
93+
"system = mm.System(name=\"stdprob5\")"
9494
]
9595
},
9696
{
@@ -182,10 +182,11 @@
182182
],
183183
"source": [
184184
"def m_vortex(pos):\n",
185-
" x, y, z = pos[0]/1e-9-50, pos[1]/1e-9-50, pos[2]/1e-9\n",
186-
" \n",
185+
" x, y, _ = pos[0] / 1e-9 - 50, pos[1] / 1e-9 - 50, pos[2] / 1e-9\n",
186+
"\n",
187187
" return (-y, x, 10)\n",
188188
"\n",
189+
"\n",
189190
"system.m = df.Field(mesh, nvdim=3, value=m_vortex, norm=Ms)\n",
190191
"system.m.sel(z=0).mpl()"
191192
]
@@ -271,7 +272,9 @@
271272
}
272273
],
273274
"source": [
274-
"system.dynamics += mm.Precession(gamma0=gamma0) + mm.Damping(alpha=alpha) + mm.ZhangLi(u=ux, beta=beta)\n",
275+
"system.dynamics += (\n",
276+
" mm.Precession(gamma0=gamma0) + mm.Damping(alpha=alpha) + mm.ZhangLi(u=ux, beta=beta)\n",
277+
")\n",
275278
"system.dynamics"
276279
]
277280
},
@@ -354,7 +357,7 @@
354357
}
355358
],
356359
"source": [
357-
"system.table.data.plot('t', 'mx')"
360+
"system.table.data.plot(\"t\", \"mx\")"
358361
]
359362
},
360363
{

examples/10-tutorial-standard-problem-fmr.ipynb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"source": [
8484
"mesh = df.Mesh(p1=(0, 0, 0), p2=(lx, ly, lz), cell=(dx, dy, dz))\n",
8585
"\n",
86-
"system = mm.System(name='stdprobfmr')\n",
86+
"system = mm.System(name=\"stdprobfmr\")\n",
8787
"\n",
8888
"system.energy = mm.Exchange(A=A) + mm.Demag() + mm.Zeeman(H=H)\n",
8989
"system.dynamics = mm.Precession(gamma0=gamma0) + mm.Damping(alpha=alpha)\n",
@@ -139,7 +139,7 @@
139139
}
140140
],
141141
"source": [
142-
"system.m.sel('z').resample((10, 10)).mpl()"
142+
"system.m.sel(\"z\").resample((10, 10)).mpl()"
143143
]
144144
},
145145
{
@@ -228,14 +228,14 @@
228228
"source": [
229229
"import matplotlib.pyplot as plt\n",
230230
"\n",
231-
"t = system.table.data['t'].values\n",
232-
"my = system.table.data['mx'].values\n",
231+
"t = system.table.data[\"t\"].values\n",
232+
"my = system.table.data[\"mx\"].values\n",
233233
"\n",
234234
"# Plot <my> time evolution.\n",
235235
"plt.figure(figsize=(8, 6))\n",
236236
"plt.plot(t, my)\n",
237-
"plt.xlabel('t (ns)')\n",
238-
"plt.ylabel('my average')\n",
237+
"plt.xlabel(\"t (ns)\")\n",
238+
"plt.ylabel(\"my average\")\n",
239239
"plt.grid()"
240240
]
241241
},
@@ -265,13 +265,13 @@
265265
"source": [
266266
"import scipy.fft\n",
267267
"\n",
268-
"psd = np.log10(np.abs(scipy.fft.fft(my))**2)\n",
269-
"f_axis = scipy.fft.fftfreq(4000, d=20e-9/4000)\n",
268+
"psd = np.log10(np.abs(scipy.fft.fft(my)) ** 2)\n",
269+
"f_axis = scipy.fft.fftfreq(4000, d=20e-9 / 4000)\n",
270270
"\n",
271-
"plt.plot(f_axis/1e9, psd)\n",
271+
"plt.plot(f_axis / 1e9, psd)\n",
272272
"plt.xlim([6, 12])\n",
273-
"plt.xlabel('f (GHz)')\n",
274-
"plt.ylabel('Psa (a.u.)')\n",
273+
"plt.xlabel(\"f (GHz)\")\n",
274+
"plt.ylabel(\"Psa (a.u.)\")\n",
275275
"plt.grid()"
276276
]
277277
},

examples/11-tutorial-deriving-fields.ipynb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,15 @@
8989
}
9090
],
9191
"source": [
92-
"system = mm.System(name='system')\n",
92+
"system = mm.System(name=\"system\")\n",
9393
"\n",
9494
"A = 1e-11\n",
95-
"H = (0.1/mm.consts.mu0, 0, 0)\n",
95+
"H = (0.1 / mm.consts.mu0, 0, 0)\n",
9696
"K = 1e3\n",
9797
"u = (1, 1, 1)\n",
98-
"system.energy = (mm.Exchange(A=A)\n",
99-
" + mm.Demag()\n",
100-
" + mm.Zeeman(H=H)\n",
101-
" + mm.UniaxialAnisotropy(K=K, u=u))\n",
98+
"system.energy = (\n",
99+
" mm.Exchange(A=A) + mm.Demag() + mm.Zeeman(H=H) + mm.UniaxialAnisotropy(K=K, u=u)\n",
100+
")\n",
102101
"\n",
103102
"system.energy"
104103
]
@@ -158,7 +157,7 @@
158157
}
159158
],
160159
"source": [
161-
"oc.compute(system.energy.effective_field, system).sel('x').mpl()"
160+
"oc.compute(system.energy.effective_field, system).sel(\"x\").mpl()"
162161
]
163162
},
164163
{
@@ -244,7 +243,7 @@
244243
],
245244
"source": [
246245
"w = oc.compute(system.energy.density, system)\n",
247-
"w.sel('x').mpl()"
246+
"w.sel(\"x\").mpl()"
248247
]
249248
},
250249
{
@@ -270,7 +269,7 @@
270269
],
271270
"source": [
272271
"E = oc.compute(system.energy.energy, system)\n",
273-
"print(f'The energy of the system is {E} J.')"
272+
"print(f\"The energy of the system is {E} J.\")"
274273
]
275274
},
276275
{
@@ -333,7 +332,7 @@
333332
"E = oc.compute(system.energy.energy, system)\n",
334333
"print(\"The system's energy is {} J.\".format(E))\n",
335334
"\n",
336-
"system.m.sel('x').mpl()"
335+
"system.m.sel(\"x\").mpl()"
337336
]
338337
},
339338
{
@@ -419,7 +418,7 @@
419418
"total_energy = 0\n",
420419
"for term in system.energy:\n",
421420
" total_energy += oc.compute(term.energy, system)\n",
422-
" \n",
421+
"\n",
423422
"print(\"The sum of energy terms is {} J.\".format(total_energy))\n",
424423
"print(\"The system's energy is {} J.\".format(oc.compute(system.energy.energy, system)))"
425424
]

examples/12-tutorial-stray-field.ipynb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@
2828
"region = df.Region(p1=(-100e-9, -100e-9, -100e-9), p2=(100e-9, 100e-9, 100e-9))\n",
2929
"mesh = df.Mesh(region=region, cell=(5e-9, 5e-9, 5e-9))\n",
3030
"\n",
31+
"\n",
3132
"def norm_fun(pos):\n",
3233
" x, y, z = pos\n",
3334
" if -50e-9 <= x <= 50e-9 and -50e-9 <= y <= 50e-9 and -50e-9 <= z <= 50e-9:\n",
3435
" return 8e5\n",
3536
" else:\n",
3637
" return 0\n",
3738
"\n",
38-
"system = mm.System(name='airbox_method')\n",
39+
"\n",
40+
"system = mm.System(name=\"airbox_method\")\n",
3941
"system.energy = mm.Exchange(A=1e-12) + mm.Demag()\n",
4042
"system.dynamics = mm.Precession(gamma0=mm.consts.gamma0) + mm.Damping(alpha=1)\n",
4143
"system.m = df.Field(mesh, nvdim=3, value=(0, 0, 1), norm=norm_fun, valid=\"norm\")"
@@ -65,7 +67,7 @@
6567
}
6668
],
6769
"source": [
68-
"system.m.norm.sel('z').mpl()"
70+
"system.m.norm.sel(\"z\").mpl()"
6971
]
7072
},
7173
{
@@ -102,7 +104,7 @@
102104
"md = oc.MinDriver()\n",
103105
"md.drive(system)\n",
104106
"\n",
105-
"system.m.sel('z').mpl(figsize=(10, 10))"
107+
"system.m.sel(\"z\").mpl(figsize=(10, 10))"
106108
]
107109
},
108110
{
@@ -159,7 +161,7 @@
159161
}
160162
],
161163
"source": [
162-
"stray_field.sel('z').mpl(figsize=(8, 8), vector_kw={'scale': 1e6})"
164+
"stray_field.sel(\"z\").mpl(figsize=(8, 8), vector_kw={\"scale\": 1e6})"
163165
]
164166
}
165167
],

0 commit comments

Comments
 (0)