Skip to content

Commit a27793b

Browse files
smidlclaude
andcommitted
motors: name anchors after the machine, not their position in the file
`Geometry2`/`Computation2` are named for being the second machine defined, not for the machine they describe. Nothing in the name says 5-phase or 40-slot, and nothing distinguishes it from the other 5-phase variants people run on branches. One module per anchor, named `<class>_<phases>f_<slots>s`: motors/motor1.py -> motors/synrm_3f_36s.py motors/motor2.py -> motors/synrm_5f_40s.py Each exports plain `Geometry` and `Computation`, so the module name carries the identity and the class names stay uniform. The numbering existed only because both machines shared a namespace; per-anchor modules remove the need for it. from motors.synrm_5f_40s import Computation, Geometry The name carries only what the anchor fixes for good -- class, phases, slots. Turns are deliberately left out: `Nc` is routinely swept, so a name containing it goes stale. Same reasoning for currents and bus voltage. Also restores the anchor definition to CONTRIBUTING (it survives on the `contributing` branch but was dropped in #23, leaving "anchor" used three times and never defined, and the sentence "add an **motors**" mid-substitution), and fixes that sentence. No behaviour change: the two anchor modules were diffed against the `motor1.py` / `motor2.py` they replace, with the class renames normalised away, and are identical apart from a one-line docstring -- including the fixes from #28 and #29, which landed in `motor2.py` while this branch was open and had to be carried across by hand. Callers must update their import path; there is no compatibility shim, so a stale import fails loudly rather than silently resolving to an aliased class. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 705fa9b commit a27793b

8 files changed

Lines changed: 39 additions & 15 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,26 @@ If you find yourself editing `machine_design/`on your own branch, stop — that'
1717
| `machine_design/optimization/` | design agnostic optimizers and geometry generators |
1818
| `machine_design/parallel_calculation/` | parallel runners for sweeping many solves at once |
1919
| `experiments/<name>/` | your run configs, the profile/objective you're studying, analysis notebooks, result artifacts, write-ups |
20-
| `motors/` | concrete machine definitions (`motor1.py`, `motor2.py`), each subclassing the base `Geometry`/`Computation` classes |
20+
| `motors/` | one module per **anchor** (a named machine), each subclassing the base `Geometry`/`Computation` classes |
2121
| `tests/` | the test suite |
2222

23-
Add a new machine by subclassing an existing `motors/motor*.py` file instead of editing an existing class in place, so old results stay reproducible.
23+
### Anchors — machines are named, not numbered
24+
25+
An **anchor** is a named machine definition: everything needed to instantiate and solve one physical machine — class, slots, phases, winding (turns, `Rs`), end-winding `Lew`, **rotor radii**, geometry generator + parameter bounds, FEA template.
26+
27+
The name carries only what the anchor fixes for good — machine class, phases, slot count. Values that are routinely swept (turns, currents, bus voltage) stay out of it, so a name never goes stale.
28+
29+
One anchor per module in `motors/`, named `<class>_<phases>f_<slots>s`:
30+
31+
| module | machine |
32+
|---|---|
33+
| `motors/synrm_3f_36s.py` | 3-phase SynRM, 36 stator slots |
34+
| `motors/synrm_5f_40s.py` | 5-phase SynRM, 40 stator slots, dq1+dq3 excitation |
35+
36+
Each exports `Geometry` and `Computation`, so the module name carries the identity and the class names stay uniform — `from motors.synrm_5f_40s import Geometry, Computation` says which machine you are solving, where `Geometry2` did not.
37+
38+
- **Derive, don't fork.** To study a variant (add magnets, change turns), subclass an existing anchor and override only what differs — do **not** edit an anchor's class in place, so old results stay reproducible. A genuinely new machine is a new anchor module.
39+
- **An anchor must declare all of the above**, rotor radii included. They are the radial window the barrier generators draw into; an anchor that does not set them cannot have a rotor built for it.
2440

2541
## Pull requests
2642

@@ -60,7 +76,7 @@ All compute goes through the SLURM queue on `bayes` — see [`bayes-queue/README
6076

6177
**I want to optimize an existing machine with an existing method** → in `experiments/<name>/`, write a config that picks an anchor + a method + your objective/constraints, and an sbatch to run it. Touch nothing shared.
6278

63-
**I want to study a new machine** → add an **motors** (PR to `main`); if it's a variant, derive it from an existing anchor. Then use it from your experiment.
79+
**I want to study a new machine** → add an **anchor** (PR to `main`); if it's a variant, derive it from an existing anchor. Then use it from your experiment.
6480

6581
**I want a new optimization method** → add it to `machine_design/optimization/` against the interface (PR to `main`). Now anyone can use it on any anchor.
6682

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Anchor `synrm_3f_36s`: 3-phase synchronous reluctance machine, 36 stator slots."""
2+
13
from ansys.aedt.core import Maxwell2d
24
from ansys.aedt.core.modeler.modeler_2d import Modeler2D
35

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
"""Anchor `synrm_5f_40s`: 5-phase synchronous reluctance machine, 40 stator slots.
2+
3+
Derives from `synrm_3f_36s`, overriding only the slotting and winding it needs for five
4+
phases. Excitation is dq1 + dq3.
5+
"""
6+
17
import numpy as np
28
from ansys.aedt.core import Maxwell2d
39

410
from machine_design.designs.computation import ComputationBase
511

6-
from .motor1 import Geometry
12+
from .synrm_3f_36s import Geometry as BaseGeometry
713

814

9-
class Geometry2(Geometry):
15+
class Geometry(BaseGeometry):
1016
def set_geom_params(self):
1117
super().set_geom_params()
1218
self.geom_params["SlotNumber"] = "40"
@@ -22,7 +28,7 @@ def set_winds_params(self):
2228
self.wind_params["Nc"] = "113"
2329

2430

25-
class Computation2(ComputationBase):
31+
class Computation(ComputationBase):
2632
def set_oper_params(self):
2733
f = 50 # [Hz]
2834
RotSpeed = 60 * f / self.geometry.PolePairs # [rpm]

‎notebooks/run.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
plot_barriers,
1616
save_params,
1717
)
18-
from motors.motor1 import Computation, Geometry
18+
from motors.synrm_3f_36s import Computation, Geometry
1919

2020
config = load_config()
2121
aedt_version = config["aedt_version"]

‎notebooks/run_optimization.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
objective,
2424
objective_transform,
2525
)
26-
from motors.motor1 import Computation, Geometry
26+
from motors.synrm_3f_36s import Computation, Geometry
2727

2828
torch.set_default_dtype(torch.float64)
2929

‎tests/test_ansys_regression.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from machine_design.config import load_config
2121
from machine_design.designs.design import Design as LiveDesign
2222
from machine_design.optimization.generators import HacklGenerator_OneLambda
23-
from motors.motor1 import Computation, Geometry
23+
from motors.synrm_3f_36s import Computation, Geometry
2424

2525
pytestmark = pytest.mark.ansys
2626

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from motors.motor1 import Computation, Geometry
5+
from motors.synrm_3f_36s import Computation, Geometry
66

77

88
@pytest.fixture
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import pytest
22

3-
from motors.motor1 import Geometry
4-
from motors.motor2 import Computation2, Geometry2
3+
from motors.synrm_3f_36s import Geometry as BaseGeometry
4+
from motors.synrm_5f_40s import Computation, Geometry
55

66

77
@pytest.fixture
88
def base_geometry():
9-
return Geometry()
9+
return BaseGeometry()
1010

1111

1212
@pytest.fixture
1313
def geometry2():
14-
return Geometry2()
14+
return Geometry()
1515

1616

1717
@pytest.fixture
1818
def computation2(geometry2):
19-
return Computation2(geometry2)
19+
return Computation(geometry2)
2020

2121

2222
def test_geom_params_overrides_slot_number_only(base_geometry, geometry2):

0 commit comments

Comments
 (0)