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

💻 💡 🤔
Marko Hinkkanen
Marko Hinkkanen

💻 🤔 💡 🧑‍🏫

Metadata

Release files for motulator-gradnet 0.1.3

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.3
File Size Uploaded Provenance Actions
motulator_gradnet-0.1.3.tar.gz 2.9 MB Without provenance Details for motulator_gradnet-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 2.9 MB

Release files / motulator_gradnet-0.1.3.tar.gz

Download URL motulator_gradnet-0.1.3.tar.gz
Size 2.9 MB
Tags Source
SHA-256 checksum
How to use checksums
e9e0408c3a3098a4589d0ec81f0384fbde60bc84c57fe610b17790092611b793
BLAKE2b-256 checksum
How to use checksums
9663c33d0978bf803d20d1879b9ef575bfff66e0f4b16a1d759f40694dc06df5
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.3-py3-none-any.whl

Download URL motulator_gradnet-0.1.3-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75e9c524cc1295e0740345ff0a013d0bed23178f022280e4660d0a1df0b6286e
BLAKE2b-256 checksum
How to use checksums
52bcac4e78d0a1ac10820bdcbe50ea2a73cf64cb9c333940fa961a809cfb1ef7
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.3

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