Skip to main content

Extension package to farn, adding support to build OSP simulation cases using FMUs.

Project description

pypi versions license ci docs

ospx

ospx is an extension package to farn, adding support to build OSP (co-)simulation cases using functional mockup units (FMUs).

ospx supports

  • building of case-specific OSP (co-)simulation configuration files
  • watching the progress of cosim, and saving final simulation results as a pandas dataframe.

Installation

pip install ospx

ospx requires the following (sub-)package:

  • dictIO: foundation package, enabling ospx to handle configuration files in dictIO dict file format.

However, dictIO gets installed automatically with ospx.

Usage Example

ospx provides both an API for use inside Python as well as a CLI for shell execution of core functions.

Reading a caseDict file and building the case-specific OSP (co-)simulation configuration files:

from ospx import OspCaseBuilder

OspCaseBuilder.build('caseDict')

The above task can also be invoked from the command line, using the 'ospCaseBuilder' command line script installed with ospx:

ospCaseBuilder caseDict

For more examples and usage, please refer to ospx's documentation.

File Format

A caseDict is a file in dictIO dict file format used with farn.

For a documentation of the caseDict file format, see File Format in ospx's documentation on GitHub Pages.

For a detailed documentation of the dictIO dict file format used by farn, see dictIO's documentation on GitHub Pages.

Development Setup

1. Install uv

This project uses uv as package manager. If you haven't already, install uv, preferably using it's "Standalone installer" method:
..on Windows:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

..on MacOS and Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

(see docs.astral.sh/uv for all / alternative installation methods.)

Once installed, you can update uv to its latest version, anytime, by running:

uv self update

2. Install Python

This project requires Python 3.10 or later.
If you don't already have a compatible version installed on your machine, the probably most comfortable way to install Python is through uv:

uv python install

This will install the latest stable version of Python into the uv Python directory, i.e. as a uv-managed version of Python.

Alternatively, and if you want a standalone version of Python on your machine, you can install Python either via winget:

winget install --id Python.Python

or you can download and install Python from the python.org website.

3. Clone the repository

Clone the dictIO repository into your local development directory:

git clone https://github.com/dnv-opensource/ospx path/to/your/dev/ospx

4. Install dependencies

Run uv sync to create a virtual environment and install all project dependencies into it:

uv sync

5. (Optional) Install CUDA support

Run uv sync with option --extra cuda to in addition install torch with CUDA support:

uv sync --extra cuda

Alternatively, you can manually install torch with CUDA support. Note 1: Do this preferably after running uv sync. That way you ensure a virtual environment exists, which is a prerequisite before you install torch with CUDA support using below uv pip install command.

To manually install torch with CUDA support, generate a uv pip install command matching your local machine's operating system using the wizard on the official PyTorch website. Note: As we use uv as package manager, remember to replace pip in the command generated by the wizard with uv pip.

If you are on Windows, the resulting uv pip install command will most likely look something like this:

uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124

Hint: If you are unsure which cuda version to indicate in above uv pip install .. /cuXXX command, you can use the shell command nvidia-smi on your local system to find out the cuda version supported by the current graphics driver installed on your system. When then generating the uv pip install command with the wizard from the PyTorch website, select the cuda version that matches the major version of what your graphics driver supports (major version must match, minor version may deviate).

6. (Optional) Activate the virtual environment

When using uv, there is in almost all cases no longer a need to manually activate the virtual environment.
uv will find the .venv virtual environment in the working directory or any parent directory, and activate it on the fly whenever you run a command via uv inside your project folder structure:

uv run <command>

However, you still can manually activate the virtual environment if needed. When developing in an IDE, for instance, this can in some cases be necessary depending on your IDE settings. To manually activate the virtual environment, run one of the "known" legacy commands:
..on Windows:

.venv\Scripts\activate.bat

..on Linux:

source .venv/bin/activate

7. Install pre-commit hooks

The .pre-commit-config.yaml file in the project root directory contains a configuration for pre-commit hooks. To install the pre-commit hooks defined therein in your local git repository, run:

uv run pre-commit install

All pre-commit hooks configured in .pre-commit-config.yaml will now run each time you commit changes.

8. Test that the installation works

To test that the installation works, run pytest in the project root folder:

uv run pytest

Meta

Copyright (c) 2024 DNV SE. All rights reserved.

Frank Lumpitzsch – @LinkedInfrank.lumpitzsch@dnv.com

Claas Rostock – @LinkedInclaas.rostock@dnv.com

Seunghyeon Yoo – @LinkedInseunghyeon.yoo@dnv.com

Distributed under the MIT license. See LICENSE for more information.

https://github.com/dnv-opensource/ospx

Contributing

  1. Fork it (https://github.com/dnv-opensource/ospx/fork)
  2. Create an issue in your GitHub repo
  3. Create your branch based on the issue number and type (git checkout -b issue-name)
  4. Evaluate and stage the changes you want to commit (git add -i)
  5. Commit your changes (git commit -am 'place a descriptive commit message here')
  6. Push to the branch (git push origin issue-name)
  7. Create a new Pull Request in GitHub

For your contribution, please make sure you follow the STYLEGUIDE before creating the Pull Request.

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

ospx-0.3.0b5.tar.gz (14.7 MB view details)

Uploaded Source

Built Distribution

ospx-0.3.0b5-py3-none-any.whl (51.9 kB view details)

Uploaded Python 3

File details

Details for the file ospx-0.3.0b5.tar.gz.

File metadata

  • Download URL: ospx-0.3.0b5.tar.gz
  • Upload date:
  • Size: 14.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ospx-0.3.0b5.tar.gz
Algorithm Hash digest
SHA256 ee9522421f69a16fb6ebe197e4a7b55c848093982ed9a4846daa121d67e0f3dd
MD5 b634fd839641578058f0b6154c635167
BLAKE2b-256 49bc81c0122a441e2443feebd010dc8b91ea78978f14eb0971292074133b3e14

See more details on using hashes here.

Provenance

The following attestation bundles were made for ospx-0.3.0b5.tar.gz:

Publisher: publish_release.yml on dnv-opensource/ospx

Attestations:

File details

Details for the file ospx-0.3.0b5-py3-none-any.whl.

File metadata

  • Download URL: ospx-0.3.0b5-py3-none-any.whl
  • Upload date:
  • Size: 51.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ospx-0.3.0b5-py3-none-any.whl
Algorithm Hash digest
SHA256 6828d59ff7c7446b7f7bae41fffeb416888ef6285c146e28d68bd9e4103ca0fc
MD5 0d01c5008a39c9ce827a874adb09b3de
BLAKE2b-256 31589cf04feacbabbfe18e1200547086888bd5924e05a5e25836b84a03b5507e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ospx-0.3.0b5-py3-none-any.whl:

Publisher: publish_release.yml on dnv-opensource/ospx

Attestations:

Supported by

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