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 (motulator and PyTorch are installed as dependencies):

pip install motulator-gradnet

The PyTorch wheels on PyPI for Linux include CUDA support and are large. The small networks of this package are trained in a reasonable time on a CPU, so a CPU-only build is sufficient. It is installed before the package with the command:

pip install --index-url https://download.pytorch.org/whl/cpu torch

The package supports motulator 0.15 and 0.16, and the support is extended after each new release of motulator has been tested. 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

License

MIT

Metadata

Release files for motulator-gradnet 0.1.0

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.0
File Size Uploaded Provenance
motulator_gradnet-0.1.0.tar.gz 2.9 MB Without provenance Details

Built distribution (wheel)

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

Total release size: 2.9 MB

Release files / motulator_gradnet-0.1.0.tar.gz

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

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

Download URL motulator_gradnet-0.1.0-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a682ae81fe951d0956da40a5b2888a4b510e6e00da3015535115f33c91097cdc
BLAKE2b-256 checksum
How to use checksums
41462540896d8bcb4aa37ed1ab5322aa095d7e84fe8448da1cef10db914d5722
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for motulator-gradnet 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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