Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ The motivation is to improve the performance of SynRMs without using permanent m

Run "run.py" for random design evaluation and "run_optimization.py" for Bayesian optimization. Ansys Electronics Desktop and PyAEDT are required.

## Configuration

Machine-specific settings (Ansys version, number of cores, workers, project directory) are read with 'load_config()' from 'machine_design.config', which merges 'machine_design/config.default.json' with an optional local override at '~/.machine_design/config.json'. Put your own values in the local file instead of editing the defaults or a script directly, so they never end up in a commit.

## Citation

If you use this code, please cite our paper:
Expand Down
6 changes: 6 additions & 0 deletions machine_design/config.default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"aedt_version": "2024.1",
"num_cores": 4,
"n_workers": 22,
"project_dir": "data"
}
17 changes: 17 additions & 0 deletions machine_design/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import json
import os

default_config_path = os.path.join(os.path.dirname(__file__), "config.default.json")
local_config_path = os.path.join(os.path.expanduser("~"), ".machine_design", "config.json")


def load_config(local_path=local_config_path):

with open(default_config_path) as f:
config = json.load(f)

if os.path.exists(local_path):
with open(local_path) as f:
config.update(json.load(f))

return config
10 changes: 6 additions & 4 deletions machine_design/parallel_calculation/runner_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
import numpy as np
from ansys.aedt.core import Desktop, Maxwell2d

from machine_design.config import load_config

# =========================================================
# CONFIGURATION
# =========================================================
AEDT_VERSION = os.getenv("AEDT_VERSION", "2026.1")
config = load_config()
AEDT_VERSION = config["aedt_version"]

PATH = "d:\\DATA\\Test"
PROJECT_DIR = os.getenv("ANSYS_PROJECT_DIR", PATH)
PROJECT_DIR = os.path.join(os.getcwd(), config["project_dir"])
BASE_PROJECT = "SynRM_orig"
DESIGN_NAME = "Design02_def_Idq"
SETUP_NAME = "Setup1"

N_WORKERS = 22 # less then number of logical processors
N_WORKERS = config["n_workers"] # less then number of logical processors


# =========================================================
Expand Down
6 changes: 4 additions & 2 deletions notebooks/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
import pandas as pd

from machine_design.config import load_config
from machine_design.designs import load_design
from machine_design.optimization import (
HacklGenerator_3BrokenLines,
Expand All @@ -16,11 +17,12 @@
)
from motors.motor1 import Computation, Geometry

aedt_version = "2024.1"
config = load_config()
aedt_version = config["aedt_version"]
num_cores = config["num_cores"]
n_designs = 50
r_stator_end = 0.7
offset = 0.7 / 2
num_cores = 4
plot_design = True

project_name = "SynRM_test"
Expand Down
6 changes: 4 additions & 2 deletions notebooks/run_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from botorch.utils.transforms import normalize, unnormalize
from gpytorch.mlls import ExactMarginalLogLikelihood

from machine_design.config import load_config
from machine_design.designs import load_design
from machine_design.optimization import (
HacklGenerator_3BrokenLines,
Expand All @@ -27,11 +28,12 @@
torch.set_default_dtype(torch.float64)


aedt_version = "2024.1"
config = load_config()
aedt_version = config["aedt_version"]
num_cores = config["num_cores"]
n_evals = 250
r_stator_end = 0.7
offset = 0.7 / 2
num_cores = 4
batch_size = 4
max_candidate_tries = 10
objective_fallback = {"torque": 1.0, "ripple": 40.0}
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ packages = [
"motors",
]

[tool.setuptools.package-data]
machine_design = ["config.default.json"]

[tool.pytest.ini_options]
testpaths = ["tests"]
markers = [
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ansys_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
import numpy as np
import pytest

from machine_design.config import load_config
from machine_design.designs.design import Design as LiveDesign
from machine_design.optimization.generators import HacklGenerator_OneLambda
from motors.motor1 import Computation, Geometry

pytestmark = pytest.mark.ansys

AEDT_VERSION = "2024.1"
AEDT_VERSION = load_config()["aedt_version"]
R_STATOR_END = 0.7
OFFSET = 0.35
SEEDS = (42, 43)
Expand Down
23 changes: 23 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json

from machine_design.config import load_config


def test_load_config_defaults(tmp_path):
config = load_config(local_path=tmp_path / "missing.json")
assert config == {
"aedt_version": "2024.1",
"num_cores": 4,
"n_workers": 22,
"project_dir": "data",
}


def test_load_config_merges_local_override(tmp_path):
local_path = tmp_path / "config.json"
local_path.write_text(json.dumps({"aedt_version": "2025.1"}))

config = load_config(local_path=local_path)

assert config["aedt_version"] == "2025.1"
assert config["num_cores"] == 4
Loading