Skip to main content

motulator-gradnet

Training of gradient-network magnetic models of synchronous machines for motulator

PyPI version

Documentation: https://aalto-electric-drives.github.io/motulator-gradnet/

This package trains gradient networks (GradNets) that model the current and flux linkage maps of synchronous machines, including spatial harmonics, from measured or finite-element data [1]. A GradNet is the gradient of a scalar state function, the magnetic energy or co-energy, so the map is a conservative vector field by construction [2], and the monotonicity of the flux-linkage–current map is ensured. The networks are defined and trained with PyTorch. A trained network is saved as a NumPy function, which the magnetic maps of motulator evaluate in the machine models and control systems without PyTorch. The package also compares the trained maps with the data.

Installation

Install the package from PyPI in a virtual environment (motulator and PyTorch are installed as dependencies). On Linux and macOS:

python3 -m venv .venv
source .venv/bin/activate
pip install --index-url https://download.pytorch.org/whl/cpu torch  # Optional
pip install motulator-gradnet

On Windows, the environment is created and activated with py -m venv .venv and .venv\Scripts\activate. The third command is optional and installs a CPU-only build of PyTorch, which is sufficient for the small networks of this package. The PyTorch wheels on PyPI for Linux include CUDA support and are large.

For development, clone the repository and install the package with pip install -e ".[dev]".

Usage

A dataset is an npz file with the complex arrays i_s_dq (stator current, A) and psi_s_dq (stator flux linkage, Vs) of the same shape, peak-valued space vectors in rotor coordinates. A dataset with spatial harmonics has also the arrays theta_m (electrical rotor angle, rad) and tau_m (electromagnetic torque per pole pair, Nm). The following example trains a flux linkage map from the measured dataset of a 5.6-kW PM synchronous reluctance machine in examples/datasets/:

import motulator.drive.gradnet as gn
from motulator.drive import utils

from motulator_gradnet import (
    PNormGradient,
    get_training_data,
    print_flux_map_errors_meas,
    train_gradnet,
)

# Base values of the machine, used to normalize the data
nom = utils.NominalValues(U=460, I=8.8, f=60, P=5.6e3, tau=29.7)
base = utils.BaseValues.from_nominal(nom, n_p=2)

# Train a flux map from every 10th data point and save it
dataset_path = "examples/datasets/baldor_meas.npz"
train_gradnet(
    dataset_path,
    base,
    is_flux_map=True,
    embed_dim=6,
    epochs=20000,
    subsample=10,
    activation=PNormGradient,
    save_model_path="flux_map.npz",
)

# The trained map is evaluated with motulator, without PyTorch
flux_map = gn.FluxMap(gn.load_gradnet("flux_map.npz"))
print(flux_map(5 + 8j))  # Flux linkage (Vs) at the current (A)

# Compare with the data points not used in the training
_, val_data = get_training_data(dataset_path, base, subsample=10)
print_flux_map_errors_meas(flux_map, val_data, base)

The map is used in the machine models and control systems of motulator through its parameter classes, e.g., SaturatedSynchronousMachinePars(n_p=2, R_s=0.63, psi_s_dq_fcn=flux_map). Complete examples, which also train current maps and maps with spatial harmonics, are in the example gallery, and simulation examples using the trained maps are in the documentation of motulator.

References

  1. Li, Foissner, Martin, Piippo, Hinkkanen, "Gradient networks for universal magnetic modeling of synchronous machines," 2026, https://arxiv.org/abs/2602.14947
  2. Chaudhari, Pranav, Moura, "Gradient networks," IEEE Trans. Signal Process., 2025, https://doi.org/10.1109/TSP.2024.3496692

Contributors

Junyi Li
Junyi Li

💻 💡 🤔
Floran Martin
Floran Martin

🤔 🔬
Tim Foißner
Tim Foißner

🤔 🔬
Marko Hinkkanen
Marko Hinkkanen

💻 🤔 💡 🧑‍🏫

Acknowledgment

This project has been sponsored by ABB Oy, the Aalto University House of AI, and the Research Council of Finland through the Centre of Excellence in High-Speed Electromechanical Energy Conversion Systems.

Metadata

Release files for motulator-gradnet 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for motulator-gradnet 0.1.9
File Size Uploaded Provenance Actions
motulator_gradnet-0.1.9.tar.gz 2.9 MB Without provenance Details for motulator_gradnet-0.1.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for motulator-gradnet 0.1.9
File Interpreter ABI Platform Actions
motulator_gradnet-0.1.9-py3-none-any.whl Python 3 none any Details for motulator_gradnet-0.1.9-py3-none-any.whl

Total release size: 2.9 MB

Release files / motulator_gradnet-0.1.9.tar.gz

Download URL motulator_gradnet-0.1.9.tar.gz
Size 2.9 MB
Tags Source
SHA-256 checksum
How to use checksums
2b3ccdf4ee4787436a6a62b64181af8ab6f669878c156794ba30de0bb3393ff6
BLAKE2b-256 checksum
How to use checksums
a9904f58da02bce19114c7e2e214830b4b1dd1cdf03da9693c738ce944f60a04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / motulator_gradnet-0.1.9-py3-none-any.whl

Download URL motulator_gradnet-0.1.9-py3-none-any.whl
Size 20.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb4d0a0cd29fbbb0256c236bed3fffe6ce8defdaa62facc7e301a9212c981379
BLAKE2b-256 checksum
How to use checksums
ac12eabb28d1be4668baa287caf1cdc89b6b48bb05bac4ce3485d42e9f15af96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for motulator-gradnet 0.1.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page