Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Port-Hamiltonian system identification

The Python package phsi-models (imported as phsi) learns port-Hamiltonian models from observed trajectories. Either analytic functions or neural networks can be fitted to represent the Hamiltonian function $H$, damping $R$ and forcing gain $G$. With applied signal $u$ and canonical interconnection matrix $J$, this gives ordinary differential equations in port-Hamiltonian form:

$$\dot x=(J-R(x))\nabla H(x)+G(x)u(t).$$

The package supports fully observed canonical coordinates, diagonal damping and one applied signal. The models can be fitted with gradient-based optimization using either an integration-scheme loss or a simulation-error loss, or, for fully analytic models, sparse regression using estimated derivatives or midpoint observations.

Installation

phsi-models requires Python 3.11 or newer. Install the alpha preview with pip:

python -m pip install 'phsi-models==1.0.0a1'

Or with uv:

uv venv
uv pip install 'phsi-models==1.0.0a1'

For an editable checkout with notebook dependencies, use python -m pip install -e '.[examples]'. This alpha precedes the paper release; the interface may still change.

Quickstart

Set up the model

import phsi

model = phsi.model(
    hamiltonian="analytic",
    damping="constant",
    forcing_gain="analytic",
    forced_state=1,  # the signal acts on the momentum equation
    gain_state=0,  # its gain depends on position
)

This example uses states ordered as (position, momentum) and learns polynomial energy and forcing gain. Use "nn" for a neural network model instead of an analytic expression. See the method notes for component choices and fitting options.

Fit observations

model.fit(X, t=t, u=u, method="integration_scheme")

Fitting bars show the latest batch loss. Set progress=False to hide the fitting progress bars.

Rows of X are observed states, t contains equally spaced observation times, and u is the applied force or voltage at those times. Lists of trajectories are also accepted. The method options are "integration_scheme", "simulation_error", "derivative" and "midpoint"; the latter two require fully analytic models. Unless separate validation data are supplied, the final 20% of each trajectory is reserved for validation.

Print, predict, save and restore

model.print()
prediction = model.simulate(x0, t=t_new, u=u_new)

model.save("model.phsi")
restored = phsi.load("model.phsi")

Printing shows the fitted equations, with analytic coefficients and neural network functions. For analytic Hamiltonians, use model.print(expand=True, decimals=4) to also show state equations with the Hamiltonian derivatives substituted and coefficients, centres and widths displayed to four decimal places. Simulation starts from x0 under the new applied signal.

Agent guide

This is a deliberately narrow implementation. The agent guide helps users and coding agents extend it—for example, by adding analytic candidate functions, changing a neural network architecture or adapting the reference physics. See AGENTS.md for the code map, extension points and checks to run.

Sources

This package accompanies the manuscript Comparing model representations and fitting methods for port-Hamiltonian system identification, by Sølve Eidnes and Håkon Noren Myhr (in preparation).

The package builds on the following code and publications, with adaptations described in the attribution notes:

Licensed under the MIT license; upstream notices are preserved in third_party/.

Metadata

Release files for phsi-models 1.0.0a1

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

Source distribution (sdist)

Source distribution for phsi-models 1.0.0a1
File Size Uploaded Provenance Actions
phsi_models-1.0.0a1.tar.gz 131.2 kB With provenance Details for phsi_models-1.0.0a1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for phsi-models 1.0.0a1
File Interpreter ABI Platform Actions
phsi_models-1.0.0a1-py3-none-any.whl Python 3 none any Details for phsi_models-1.0.0a1-py3-none-any.whl

Total release size: 175.2 kB

Release files / phsi_models-1.0.0a1.tar.gz

Download URL phsi_models-1.0.0a1.tar.gz
Size 131.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ab128147a146374132c188bb6c74cad946b670ec97fcd20a40977530bfa3ddb7
BLAKE2b-256 checksum
How to use checksums
6a6c49bd7b995eaf09866a5771048ea85ad23f9a6eaaefeab19117c98fa09e20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / phsi_models-1.0.0a1-py3-none-any.whl

Download URL phsi_models-1.0.0a1-py3-none-any.whl
Size 44.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5357ef1641158104eeb934e037c875ce77f8add65590d2e4a882d4fd8552ebb8
BLAKE2b-256 checksum
How to use checksums
091be8fa96ea70373d2fb7a8711248d5ccc6d69a768ec02fc9a4655716cee24f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Security for phsi-models 1.0.0a1

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for phsi_models-1.0.0a1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release
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