Skip to main content

CppModel for Python

Write CppModel simulations in Python. Every run fetches the inputs and parameters posted for it in your CppModel workspace and submits its execution there, just like a C or C++ simulation built with the CppModel SDK.

pip install cppmodel

Wheels are available for Linux (x86_64 and aarch64, glibc 2.28+), Windows (x64 and ARM64) and macOS 11+ (Apple silicon and Intel), for Python 3.9 and later. Each wheel contains the CppModel library, so nothing else needs installing.

A simulation

import sys
import cppmodel


class Heater(cppmodel.Simulation):
    def init(self):
        self.temperature = 20.0

    def step(self, time_ms):
        setpoint = self.inputs.get("Setpoint", 22.0)        # input, with its fallback
        gain = self.parameters.get("HeaterGain", 0.05)      # parameter, with its fallback

        heater_on = self.temperature < setpoint             # the controller under test
        self.temperature += gain if heater_on else -0.01

        self.outputs["Temperature"] = self.temperature
        self.outputs["HeaterOn"] = heater_on
        self.outputs["CppModel.Step"] = time_ms
        self.outputs["CppModel.StepResult"] = self.temperature < setpoint + 1.0


with Heater("Example - Heater (Python)", total_time_ms=60_000, step_ms=100) as simulation:
    sys.exit(simulation.run())

run() fetches the pending inputs and parameters, calls init(), then step(time_ms) for every step from 0 to total_time_ms, then finalize(), and submits the execution. It returns 0 when every step passed, otherwise the CppModel.Step of the first step whose CppModel.StepResult was 0.

An exception raised in init(), step() or finalize() (Ctrl-C included) aborts the run, submits nothing and is re-raised by run().

Instead of subclassing, you can pass functions that take the simulation as their first argument:

def ramp(sim, time_ms):
    sim.outputs["Ramp"] = time_ms

sim = cppmodel.Simulation("Ramp", total_time_ms=1000, step_ms=100, step=ramp)
sim.run()

Inputs, outputs and parameters

sim.inputs.get(name, fallback) The input's value at the current step, or fallback (recorded as its value)
sim.inputs[name] Same, with fallback 0
sim.inputs.load([{"label", "x", "y"}, ...]) Loads input series locally (x in ms)
sim.outputs[name] = value Sets an output; it holds until set again and is recorded every step. Values are numbers; bools become 1/0
sim.parameters.get(name, fallback) The parameter, storing fallback when it isn't set; a fetched value replaces the fallback
sim.parameters[name] = value Sets a parameter that fetched values never replace
sim.parameters[name] The parameter, or KeyError
sim.results() The execution as submitted: {"inputs", "results", "parameters", ...}

Inputs and outputs are numbers. Parameters keep their JSON type: numbers, bools, strings, lists, dicts and None. All three support in, len(), iteration and keys().

Workspace access

A run needs to sign in to your workspace:

  • Scripts, CI: set CPPMODEL_USERNAME and CPPMODEL_PASSWORD.
  • Without the workspace: create the simulation with offline=True. Nothing is fetched or submitted.

Without credentials, the first run prints a sign-in link and waits until you've signed in. The link goes to the process's standard output, which Jupyter doesn't show, so use credentials in notebooks.

Fingerprint

Each execution records a CppModel.BinaryFingerprint of the simulation's code, so the workspace can tell runs of the same code from runs of changed code. It is the fingerprint of the file your Simulation subclass (or step function) is defined in. Set sim.fingerprint_file to use another file.

Errors

A failing library call raises cppmodel.CppModelError; its status is a cppmodel.Status.

License

The CppModel library is proprietary software of Control Edge AB, used under the CppModel Terms of Service; see LICENSE. The package also contains third-party components under their own licenses, in licenses/.

Metadata

Release files for cppmodel 0.9.0

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

Built distributions (wheels)

Table of built distributions (wheels) for cppmodel 0.9.0
File
cppmodel-0.9.0-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details
cppmodel-0.9.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
cppmodel-0.9.0-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details
cppmodel-0.9.0-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details
cppmodel-0.9.0-py3-none-macosx_11_0_universal2.whl Python 3 none macOS 11.0+ universal2 (ARM64, x86-64) Details

Total release size: 18.0 MB

Release files / cppmodel-0.9.0-py3-none-win_arm64.whl

Download URL cppmodel-0.9.0-py3-none-win_arm64.whl
Size 2.9 MB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
d14120ad6cb5ffdfd7468fc7cd078c95e2f4b3aa8ec49aa72176e0b0285793b8
BLAKE2b-256 checksum
How to use checksums
1de1e30f0a577278ba3c757cadf05705fadc7e15d0f5b15ebdaa36c50f5429f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cppmodel-0.9.0-py3-none-win_amd64.whl

Download URL cppmodel-0.9.0-py3-none-win_amd64.whl
Size 2.6 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
0f2ca697f6310e81bd02d87a651d3a5b8f3d45415912f1effd8cc1efb765fd7d
BLAKE2b-256 checksum
How to use checksums
5c426aca99182b7112088a3b271a2ff40d9403a1787e2c25b7eae1107cd8a6b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cppmodel-0.9.0-py3-none-manylinux_2_28_x86_64.whl

Download URL cppmodel-0.9.0-py3-none-manylinux_2_28_x86_64.whl
Size 3.6 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
b4c6ced6c290e7013ff4ef77d2ab4670d91c972fd217acda2312a7a09fc5e54a
BLAKE2b-256 checksum
How to use checksums
52e5d29aec0f6d6aa690d799f9e45426043cb60bf5c913864ce5aac07123ade0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cppmodel-0.9.0-py3-none-manylinux_2_28_aarch64.whl

Download URL cppmodel-0.9.0-py3-none-manylinux_2_28_aarch64.whl
Size 3.8 MB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
fbaca84164736627aba57b941ed07c34cc47b8bb3e9b4c391a427d4a0c9ce208
BLAKE2b-256 checksum
How to use checksums
739f69be2143602a209a7ee98000c4757a05a8ee9990203eeb273822358c32e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cppmodel-0.9.0-py3-none-macosx_11_0_universal2.whl

Download URL cppmodel-0.9.0-py3-none-macosx_11_0_universal2.whl
Size 5.2 MB
Tags Python 3 macOS 11.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
6f4e88f0657186c430656509d293f643a1c5f6c1bb676ac6eadbbb63612513c8
BLAKE2b-256 checksum
How to use checksums
df64f9eb36ab4c02a80eee14f3a83433e7f1e85aca90b4bd4c6b4f3ec7371941
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Security for cppmodel 0.9.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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