A generic class which all new Connectors (integrations which provide Simvue tracking for Non-Python software) should inherit from.
Project description
Simvue Integrations - Connectors Template
A template which all new Connectors (integrations which provide Simvue tracking for Non-Python software) should inherit from.
Website • Documentation
Implementation
A customised WrappedRun class has been created which has the following methods:
Pre Simulation
The _pre_simulation method is called when the launch() method is called, but before the file monitor is started. This means that it should include:
- Upload of any input or code files
- Adding any tags or metadata which are present before the simulation begins
- Creating alerts
- Logging events messages required before the simulation begins
- Adding the process for the simulation, using parameters which will be input into the launch method
Because this class inherits from the base Simvue Run class, all methods associated with that are available through self.
You should also call the functionality from the WrappedRun class at the top of your method using super()._pre_simulation() - this creates a trigger which can be used to abort the file monitor, and checks that a simvue Run has been initialized before the launch method was called.
During Simulation
The _during_simulation method is called when the launch() method is called, and within the self.file_monitor context manager. This is an instance of the FileMonitor class from multiparser, which monitors any files which you wish to track. You should include all of your multiparser code inside this method, eg:
- Calls to the .track() method, detailing a file to read and the methods or functions used to process and upload data from it
- Calls to the .tail() method, detailing a file to read line by line as it is written and the methods or functions used to process and upload data from it
Post Simulation
The _post_simulation method is called when the launch() method is called, but after the file monitor is finished. This means that it should include:
- Upload of any output files
- Adding any tags or metadata which are generated after the simulation finishes
- Logging events messages required after the simulation finishes
Because this class inherits from the base Simvue Run class, all methods associated with that are available through self. You should also call the functionality from the WrappedRun class at the bottom of your method using super()._post_simulation() - this adds support for soft aborts of simulation, and termination of simulations with alerts.
Launch
The launch method is the overall method which starts the file monitor and calls the three methods above. This should be overriden to require the user to provide any inputs relevant to running the simulation, for example the path to an executable, the path of an input file, and/or the path of an output directory.
Once you have created your set of required parameters, make sure to call the parent launch method: super().launch().
Load
The load method should allow you to load a set of results from the simulation which have already been run into the Simvue server. This should reuse as many of the other methods already defined as possible, such as the callback and/or parser functions, but note that it will not launch the file monitor.
Installation
To install and use this connector, first create a virtual environment:
python -m venv venv
Then activate it:
source venv/bin/activate
And then use pip to install this module:
pip install simvue-connector
Configuration
The service URL and token can be defined as environment variables:
export SIMVUE_URL=...
export SIMVUE_TOKEN=...
or a file simvue.toml can be created containing:
[server]
url = "..."
token = "..."
The exact contents of both of the above options can be obtained directly by clicking the Create new run button on the web UI. Note that the environment variables have preference over the config file.
Usage example
from simvue_connector.connector import WrappedRun
import multiparser.parsing.tail as mp_tail_parser
# Create a new Connector class which inherits from WrappedRun
class TemperatureRun(WrappedRun):
script_path: pathlib.Path = None
# Override the `_pre_simulation` method to launch the process
def _pre_simulation(self):
# Call the base method first
super()._pre_simulation()
# Add a process to the run using `add_process`
self.add_process(
identifier="heating_experiment",
executable="bash",
script=self.script_path,
completion_trigger=self._trigger # Sets a threading Event once the simulation is completed
)
# Override the `_during_simulation` method to track the temperature data
def _during_simulation(self):
# Use the `tail` method of the Multiparser `FileMonitor` object to track file, line by line
self.file_monitor.tail(
path_glob_exprs=str(self.script_path.with_suffix(".csv")),
parser_func=mp_tail_parser.record_csv, # Use the built-in CSV parser, which returns a dictionary of data and metadata as each line is written
callback=lambda csv_data, metadata: self.log_metrics( # Use data from those two dictionaries to log a metric:
{'sample_temperature': csv_data["Temperature"]},
time=csv_data["Time"],
step=csv_data["Step"],
)
)
# Override the `_post_simulation` method to upload the final CSV file of temperature data
def _post_simulation(self):
self.save_file(self.script_path.with_suffix(".csv"), category="output")
# And finally call the base method
super()._post_simulation()
# Override the `launch` method to accept the path to the bash script
def launch(self, script_path: str):
self.script_path = script_path
# Call the base `launch` method to call the above methods in the correct order
super().launch()
License
Released under the terms of the Apache 2 license.
Citation
To reference Simvue, please use the information outlined in this citation file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simvue_connector-1.1.1.tar.gz.
File metadata
- Download URL: simvue_connector-1.1.1.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d471820c0184489e3ccf74a6e9760249047124373792ce64b9ff5e1370096d5
|
|
| MD5 |
5213ce5cb2d2cf05caba0fd09726ea9b
|
|
| BLAKE2b-256 |
3e45563c096f4176e714c3e52ba4c53ea4ec0537df35f4c74f7dea665b087008
|
Provenance
The following attestation bundles were made for simvue_connector-1.1.1.tar.gz:
Publisher:
deploy.yaml on simvue-io/connectors-generic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simvue_connector-1.1.1.tar.gz -
Subject digest:
9d471820c0184489e3ccf74a6e9760249047124373792ce64b9ff5e1370096d5 - Sigstore transparency entry: 1262930778
- Sigstore integration time:
-
Permalink:
simvue-io/connectors-generic@369b3d00876bd748e334f371dd1c9d48c9b3550b -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/simvue-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yaml@369b3d00876bd748e334f371dd1c9d48c9b3550b -
Trigger Event:
push
-
Statement type:
File details
Details for the file simvue_connector-1.1.1-py3-none-any.whl.
File metadata
- Download URL: simvue_connector-1.1.1-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f94582da2aae345d80deefddf5bf9bf7c5a0d63bd7059d5eea36bf744ca915b8
|
|
| MD5 |
d6fc9e45775a628bef1ab297147a4e6c
|
|
| BLAKE2b-256 |
0a167b15e1bcd23f05f665f98aab5fc782377a8989f67800b8f8569e4a5a863e
|
Provenance
The following attestation bundles were made for simvue_connector-1.1.1-py3-none-any.whl:
Publisher:
deploy.yaml on simvue-io/connectors-generic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simvue_connector-1.1.1-py3-none-any.whl -
Subject digest:
f94582da2aae345d80deefddf5bf9bf7c5a0d63bd7059d5eea36bf744ca915b8 - Sigstore transparency entry: 1262930779
- Sigstore integration time:
-
Permalink:
simvue-io/connectors-generic@369b3d00876bd748e334f371dd1c9d48c9b3550b -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/simvue-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yaml@369b3d00876bd748e334f371dd1c9d48c9b3550b -
Trigger Event:
push
-
Statement type: