Skip to main content

Python bindings for OCTypes, SITypes, and RMNLib C libraries for scientific computing with units and dimensional analysis

Project description

RMNpy

Python bindings for OCTypes, SITypes, and RMNLib C libraries.

CI Status

🚀 Setting up on a new computer? See docs/development/NEW_COMPUTER_SETUP.md for quick setup or docs/development/ENVIRONMENT_SETUP.md for detailed instructions.

Overview

RMNpy provides Python access to three scientific computing C libraries:

  • OCTypes: Objective-C style data structures and memory management
  • SITypes: Scientific units and dimensional analysis
  • RMNLib: High-level analysis and computation tools

Features

  • Type-safe conversion between Python and C data structures
  • Scientific units and dimensional analysis
  • High-performance numerical computations
  • Memory-safe interface to C libraries

Installation

For Development (Recommended)

See docs/development/ENVIRONMENT_SETUP.md for complete instructions.

Quick version:

# Clone the repo with all C libraries
git clone https://github.com/pjgrandinetti/OCTypes-SITypes.git
cd OCTypes-SITypes

# Build required C libraries first
cd OCTypes && make && make install && cd ..
cd SITypes && make && make synclib && make install && cd ..
cd RMNLib && make && make synclib && make install && cd ..

# Set up Python environment
cd RMNpy
conda env create -f environment.yml
conda activate rmnpy
pip install -e .

For End Users (When Available)

pip install rmnpy

Platform Support:

  • Requirements

  • Linux/macOS: Python 3.11-3.12

  • Windows: Python 3.12 only (requires MSYS2 environment)

Windows (MSYS2/Mingw-w64 Python)

To install RMNpy with C99-based Cython extensions on Windows you must use the MSYS2 MINGW64 Python runtime:

  1. Install MSYS2 and open the MSYS2 MinGW64 shell.

  2. Update packages and install dependencies:

    pacman -Syu             # first-time update
    pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-python-pip \
                 mingw-w64-x86_64-openblas mingw-w64-x86_64-lapack \
                 mingw-w64-x86_64-curl mingw-w64-x86_64-make
    
  3. Create and activate a virtual environment (so pip can install into it):

    python -m pip install --upgrade pip virtualenv
    python -m virtualenv venv
    source venv/bin/activate
    
  4. Install RMNpy and test extras:

    pip install numpy pytest pytest-cov
    pip install -e .[test]
    
  5. Run your scripts or pytest from this venv; it uses MinGW-built extensions compatible with Windows.

Using Conda-forge MSYS2 Environment (Optional)

If you prefer managing dependencies with conda, you can provision an MSYS2 toolchain via conda-forge:

conda create -n rmnpy-win python=3.12 pip m2-msys2-runtime m2-gcc m2-gcc-fortran m2-openblas m2-lapack m2-curl m2-make virtualenv -c conda-forge
conda activate rmnpy-win
# (Optional) isolate further via virtualenv within conda env:
python -m venv venv
source venv/bin/activate
pip install -e .[test]

Quick Start

from rmnpy.sitypes import Scalar, Unit, Dimensionality

# === Flexible Scalar Creation ===

# Single string expressions (value + unit)
energy = Scalar("100 J")           # 100 Joules
velocity = Scalar("25 m/s")        # 25 meters per second

# Single numeric values (dimensionless)
ratio = Scalar(0.75)               # 0.75 (dimensionless)
count = Scalar(42)                 # 42 (dimensionless)
impedance = Scalar(3+4j)           # Complex number

# Value and unit pairs
distance = Scalar(100, "m")        # 100 meters
power = Scalar(2.5, "W")           # 2.5 Watts
current = Scalar(3+4j, "A")        # Complex current

# Named parameters
unit_meter = Scalar(expression="m")                  # 1 meter
force = Scalar(value=9.8, expression="kg*m/s^2")    # 9.8 Newtons

# === Scientific Calculations with Automatic Units ===

# Basic physics calculations
time = Scalar(2, "s")
speed = distance / time             # Result: 50 m/s (automatic unit derivation)
acceleration = Scalar(9.8, "m/s^2")
force = Scalar(5, "kg") * acceleration  # Result: 49 N (automatic units)

# Unit conversions
speed_kmh = speed.to("km/h")     # Convert to km/h
speed_si = speed.to_coherent_si()        # Convert to SI base units

# === Dimensional Analysis & Safety ===

# Automatic dimensional validation
try:
    invalid = distance + time        # Error: cannot add length + time
except RMNError:
    print("Dimensional mismatch caught!")

# Complex calculations with unit tracking
kinetic_energy = 0.5 * Scalar(2, "kg") * speed**2  # Result: 2500 J

# === Unit and Dimensionality Operations ===

# Create and manipulate units
meter = Unit("m")
second = Unit("s")
velocity_unit = meter / second       # Result: m/s

# Dimensional analysis
length_dim = Dimensionality.for_quantity(kSIQuantityLength)
time_dim = Dimensionality.for_quantity(kSIQuantityTime)
velocity_dim = length_dim / time_dim # Result: L/T

print(f"Speed: {speed}")             # "50 m/s"
print(f"Unit: {speed.unit}")  # "m/s"
print(f"Dimensionality: {speed.dimensionality}")  # "L/T"

Development

This package is built using Cython to provide efficient bindings to the underlying C libraries.

Setting up the development environment

  1. Create conda environment:

    conda env create -f environment-dev.yml
    conda activate rmnpy
    
  2. Sync libraries from local development:

    make synclib  # Copy libraries from local ../OCTypes, ../SITypes, ../RMNLib
    
  3. Install in development mode:

    pip install -e .
    

Building from source

git clone https://github.com/pjgrandinetti/RMNpy.git
cd RMNpy
conda env create -f environment.yml
conda activate rmnpy
make synclib  # Copy libraries from local development
pip install -e .

Makefile targets

  • make synclib - Copy libraries from local ../OCTypes, ../SITypes, ../RMNLib directories
  • make download-libs - Download libraries from GitHub releases (future feature)
  • make clean - Remove generated C files and build artifacts
  • make clean-libs - Remove local libraries to force re-download
  • make rebuild - Clean libraries and rebuild Python package
  • make test - Run the test suite
  • make status - Check library status

See docs/development/DEVELOPMENT.md for complete development workflows.

Documentation

User Documentation

Development Documentation

License

See LICENSE file for details.

Contributing

Contributions are welcome! Please see the development documentation for guidelines.

Trigger CI after Unit test fix

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

rmnpy-0.2.0.tar.gz (1.0 MB view details)

Uploaded Source

Built Distributions

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

rmnpy-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (20.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

rmnpy-0.2.0-cp312-cp312-macosx_13_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

rmnpy-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (20.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

rmnpy-0.2.0-cp311-cp311-macosx_13_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

Details for the file rmnpy-0.2.0.tar.gz.

File metadata

  • Download URL: rmnpy-0.2.0.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rmnpy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 dc2b464cd60bc03a518c2ae3ed496e10d3c480da947ed7cb33c7f491ec299b81
MD5 55007f9923990a3d77cd2a29438d377c
BLAKE2b-256 612a72f8c031405162c942dd0a295c822024d2e96fe84e5c586926a811996c41

See more details on using hashes here.

File details

Details for the file rmnpy-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rmnpy-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4d6bcf0bf3cc816cf34ba31e75045ba7c441fdc0b3dc932891fb49bb51c86567
MD5 58953dba57ae6a3c7989a268670b5248
BLAKE2b-256 ec7dc296a8e4eed7d1b691274b18d45b79fbcfc9c1daa93035f5579f52f9d506

See more details on using hashes here.

File details

Details for the file rmnpy-0.2.0-cp312-cp312-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for rmnpy-0.2.0-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 b7595c718aa6de17ad3133201ce4586cab2cd65ceca2dca0ce067fa46122e133
MD5 12b8c553f4e6fd785093210aee7be3b0
BLAKE2b-256 a63b15e9edfe40c1f96161282631e650f3f80993315b7a78a3e030923db190f3

See more details on using hashes here.

File details

Details for the file rmnpy-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rmnpy-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82540fe0dc016cefa744e731b471dfdfedf9a5b37b6da8e12d0b8a02cd4b1dee
MD5 66ee3c15776c3ccf2ad6cfecd1753941
BLAKE2b-256 a2ed6fa5d090661dfdbbdaca3a132933257449a361f23cab5f51ca87a11d7c13

See more details on using hashes here.

File details

Details for the file rmnpy-0.2.0-cp311-cp311-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for rmnpy-0.2.0-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 75da12654f4188c03cb0a12e045eefd387f2fa7c1d81b02da34cad79e33d3bc1
MD5 3d348c2a69ae6c3c548bcfe78d462a05
BLAKE2b-256 346a39becc648155ba9561e4296385c6715399ef5541ff8f35bab3e71a1bb742

See more details on using hashes here.

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