Getting started#
PyTwin provides Pythonic access to twin runtimes that were generated using Ansys Twin Builder and Ansys TwinAI.
PyTwin supports twin runtimes generated using 2023 R1 and later.
Licensing requirements#
For twin runtimes generated with 2023 R1, the Ansys License Manager must have a license file with the
twin_builder_deployer feature available to use PyTwin.
For twin runtimes generated with 2023 R1 SP1 and later versions:
if the TWIN file is exported as ‘licensed’, the Ansys License Manager must have a license file with the
twin_runtimefeature available to use PyTwin.if the TWIN file is exported as ‘unlicensed’, no license is needed to use PyTwin
Both the features twin_builder_deployer and twin_runtime are included in the
TwinAI license file. Here is how you define the environment variable for specifying the location of
Ansys License Manager:
ANSYSLMD_LICENSE_FILE={PORT_NUMBER}@{SERVER_NAME}
Twin runtime dependencies#
The pytwin package allows you to execute deployment workflows based on TWIN files
generated by Ansys Twin Builder.
TWIN files are generally made up of several types of models, including system-level models, ROMs
(reduced order models), third-party models, and FMU (Functional Mock-up Unit) files. Each of these
models can have specific runtime dependencies. For example, Modelica models cross-compiled with
TwinAI on Ubuntu 20.04 have a dependency on libgfortran5.
In particular, the current version of pytwin requires Microsoft Visual C++ 2022 Redistributable (x64) version 14.36 or later.
When executing twin runtimes through PyTwin on a specific environment, all dependencies of the twin runtimes, including the ones of their constitutive models, must be properly installed and made available in that environment.
Linux C++ runtime#
On Linux, PyTwin preloads its bundled libstdc++.so.6 before importing its
third-party dependencies. This applies to all public APIs, including TwinModel
and TwinRuntime, and avoids using an older system C++ runtime when PyTwin is
imported first. The bundled library’s system dependencies must still be available.
Import PyTwin before other native packages, particularly on systems such as Rocky Linux 8.10 whose system C++ runtime might not provide the symbol versions required by the Twin Runtime SDK:
import pytwin
import numpy as np
Preloading during import cannot reliably replace an incompatible C++ runtime already loaded in the Python process. In that case, restart Python with a compatible system or environment C++ runtime, or preload PyTwin’s bundled library before Python starts:
LD_PRELOAD=/absolute/path/to/pytwin/twin_runtime/libstdc++.so.6 python your_script.py
Replace the path with the bundled library in your installed package. Do not import PyTwin to discover this path in a process where imports already fail. For notebooks, configure the environment before starting the kernel and restart any existing kernel. If other native packages cannot share a compatible runtime, run PyTwin in a separate process with its own startup environment.
Install the package#
The pytwin package supports Python 3.10 through Python 3.14 on Windows and Linux.
Install the latest release from PyPi with this command:
pip install pytwin
For PyTwin workflows evaluating and post processing field results from TBROM included in a TWIN file (see Examples), you need to install additional dependencies with :
pip install pytwin[graphics]
If you plan on doing local development of PyTwin with Git, install the latest release with this code:
git clone https://github.com/ansys/pytwin.git
cd pytwin
pip install pip -U
pip install -e .
Any changes that you make locally are reflected in your setup after you restart the Python kernel.
Additional PyAnsys libraries#
You can install and use these additional PyAnsys libraries:
PyAEDT, which provides access to Ansys Twin Builder for model creation and the generation of twin runtimes.