Skip to main content

Explicit Units and Dimensional Analysis for Scientific Python

Project description

PicoUnits

A runtime dimensional environment and unit-aware DSL for scientific computing in Python

PicoUnits: Usage

Python Version WIP License

Picounit is a dimensional environment designed for computational science. It serves to make simulation code structurally correct and includes:

  • Pluggable unit systems: Define custom base dimensions (Unit Frames) for your domain
  • Configuration format: .uiv files with embedded, validated units & .ut for unit types
  • Boundary validation: @unit_validator decorators catch errors at function interfaces
  • Full numeric support: Real, complex, and array-based vectors

What is .uiv & .ut?

Both are dimensionally aware formats, .ut (unit types) encodes custom base units for your system and .uiv (unit informed values) encodes value, unit pairs:

# Coilgun Units - Derived from Base Dimensions (kg, m, s, etc)
[version]
format: 0.1.0

[units]
ρ: kg/m^3
V: kg*m^2*s^-3*A^-1

All value : unit pairs exist in the form value prefix(unit), for example:

[version]
format: 0.1.0
unit_frame: units.ut

[notes]
# Analytical model for a multi-stage coil-gun
# Models electrical, magnetic and motional dynamics

[model]
number_stages: 10

# Millimeter -> prefix `m` and unit `m` hence prefix(unit), m(m)
stage_gap: 10 m(m)
voltage: 18 (V)
current_limit: 40 (A) 
time_steps: 50 u(s)
atmospheric_density: 1.225 (ρ)

Quick Start

from picounits import unit_validator, VOLTAGE, CURRENT, RESISTANCE

@unit_validator(VOLTAGE)
def ohm_law(i, r):
    return i * r

# Correct usage
v = ohm_law(10 * CURRENT, 5 * RESISTANCE) 
print(v) # Output: 50.0 (kg·m²·s⁻³·A⁻¹) (Derived units need to be pulled in via .ut)

# This would raise a DimensionError:
# ohm_law(10 * VOLTAGE, 5 * RESISTANCE)

Documentation

Full documentation is available at docs, and beginner to advanced examples are available at examples

Installation

To install:

# Recommended for most users
pip install PicoUnits

or use setuptools locally:

git clone https://github.com/wgbowley/PicoUnits.git
cd PicoUnits
pip install -e .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

picounits-1.0.5.tar.gz (88.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

picounits-1.0.5-py3-none-any.whl (54.7 kB view details)

Uploaded Python 3

File details

Details for the file picounits-1.0.5.tar.gz.

File metadata

  • Download URL: picounits-1.0.5.tar.gz
  • Upload date:
  • Size: 88.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for picounits-1.0.5.tar.gz
Algorithm Hash digest
SHA256 cbd1f4cbc33a6b8dc3f3b000bd3825a582661f095d7768cf1892d1f2078df0d4
MD5 b90542a5b702e097277d907adfceb0ed
BLAKE2b-256 11146a1e612c29f560d3570f77cba33371030045e1736d902854eab56800d60b

See more details on using hashes here.

Provenance

The following attestation bundles were made for picounits-1.0.5.tar.gz:

Publisher: publish_picounits.yml on wgbowley/PicoUnits

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file picounits-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: picounits-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 54.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for picounits-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 99470f79c14b2dc2796fbfce1fc8540b311b277fcb6f19e5156a3afa328aa34e
MD5 173b4a758fa196fa39b3f87aee1d8463
BLAKE2b-256 f5b0dafbd8b3c52c592f8a9c999ecb8e3de9736f8837ae0f3a22f2ab92a9c8c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for picounits-1.0.5-py3-none-any.whl:

Publisher: publish_picounits.yml on wgbowley/PicoUnits

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page