Skip to content

overview

Use an external OpenSees executable to run an exported Tcl model.

The runtime API connects a Python session to a solver. First resolve and validate the executable with setup(), then invoke an existing Tcl file with run(). It neither builds the model nor submits a remote job. Use Jobs when you need staged tasks, scheduling, or remote submission rather than a direct solver invocation.

Configure A Solver And Run One Model

Assume the model has already been exported to example_outputs/case/model.tcl and a compatible OpenSees build is installed. Replace the executable placeholder with the actual file on your machine:

from pathlib import Path
from femora import runtime

info = runtime.setup("local", executable=Path("path/to/OpenSees"))
print(info.executable)
print(info.version)

script = Path("example_outputs/case/model.tcl").resolve()
completed = runtime.run(script, executable=info.executable, show_output=True)
print(completed.returncode)

setup() starts a short validation script, not your model. It returns a RuntimeInfo describing the resolved executable. It also sets FEMORA_OPENSEES in this Python process so later runtime calls can reuse that choice; it does not permanently configure another terminal.

run() starts the actual solver and waits until it exits. It returns a subprocess.CompletedProcess on success. This does not validate numerical accuracy or guarantee every possible Tcl failure was detected.

Where Output Goes

By default, the solver's working directory is the Tcl file's parent directory. Relative recorder paths and Tcl file operations are interpreted by the solver from that working directory. Use cwd=... deliberately when the model expects another layout; runtime does not create that directory for you.

The runtime creates no stage/task folders, manifest.json, or stdout.log. Those belong to other execution layers or your own program. Successful calls retain combined stdout/stderr in completed.stdout. You can save it explicitly:

log = script.parent / "solver_output.log"
log.write_text(completed.stdout, encoding="utf-8")

That log is written by this example after success, not automatically during execution. Captured output is held in memory; consider its size for long runs. Recorder files are separate numerical output and remain where the Tcl model writes them. Read those using Results & Postprocessing.

Progress And Failure

Femora-managed FEMORA_PROGRESS records become progress bars. Warning/error diagnostics are displayed even with the default show_output=False; ordinary solver lines are also displayed when show_output=True. Displaying a warning does not itself turn the call into a failure.

To handle a failed model invocation, replace the direct run() call above with this guarded call rather than running the model a second time:

try:
    completed = runtime.run(script, executable=info.executable)
except runtime.RuntimeExecutionError as error:
    print(str(error))

A nonzero exit status or a managed analysis error record raises RuntimeExecutionError. Its message gives the failure summary and, when available, the last 20 captured output lines. There is no returned completed process on that path, no partial Jobs RunResult, and no automatic retry or rollback of recorder files already written.

If configuration fails before execution, inspect RuntimeSetupError instead. A missing Tcl file raises FileNotFoundError. See the error pages for the distinctions and the expanded function documentation below for complete parameters.

Use executable discovery instead of an explicit path

For local setup, an explicit executable file takes precedence over FEMORA_OPENSEES; otherwise OpenSees is discovered on PATH. If a selected explicit/environment path is invalid, setup reports the problem rather than silently choosing a different executable.

info = runtime.setup("local")
print(info.executable)

run() can resolve the same choices, but does not perform setup's validation probe. Pass info.executable when you want the choice to be explicit.

Prepare the bundled Google Colab runtime

In a supported Colab environment with Femora already installed:

info = runtime.setup("colab")
print(info.executable, info.tcl_library, info.installed)

Colab setup can download and install a bundled runtime, verifies its published checksum, checks the Tcl library, and probes the launcher. A valid existing launcher is reused unless force=True. Use a dedicated install_dir: installation/reinstallation can replace that directory and its contents. Network, filesystem, and archive errors can propagate in addition to the runtime-specific validation errors. This is not a generic cloud deployment API.

Where To Go Next

Functions:

Name Description
setup

Resolve or prepare a solver and validate startup with a short Tcl probe.

run

Invoke one exported Tcl model and wait for the solver to finish.

Functions:

setup

setup(environment: str = 'auto', *, executable: Optional[Union[str, Path]] = None, install_dir: Optional[Union[str, Path]] = None, release_url: str = DEFAULT_COLAB_RELEASE_URL, force: bool = False, timeout: float = 120.0) -> RuntimeInfo

Resolve or prepare a solver and validate startup with a short Tcl probe.

This does not run the model, install arbitrary Python dependencies, or request remote resources. On success FEMORA_OPENSEES is set for the current Python process and inherited by subsequently started child processes.

Parameters:

Name Type Description Default
environment str

"auto", "local", "colab", or "google_colab". Automatic mode detects Google Colab and otherwise resolves a local executable.

'auto'
executable str | Path | None

Executable file path, not a shell command. Local resolution uses this value, then FEMORA_OPENSEES, then PATH discovery of OpenSees/OpenSees.exe. An invalid selected path is not silently replaced by a PATH candidate.

None
install_dir str | Path | None

Dedicated Colab installation directory; defaults to /content/opensees. Ignored in local mode.

None
release_url str

Colab bundle release directory containing the archive and published SHA-256 checksum. Ignored in local mode.

DEFAULT_COLAB_RELEASE_URL
force bool

Reinstall the Colab bundle even if its launcher exists; ignored in local mode.

False
timeout float

Per-download timeout in seconds, not a model execution limit. The separate startup probe has a 30-second timeout.

120.0

Returns:

Name Type Description
info RuntimeInfo

Validated configuration. Version can be None even when the probe succeeds.

Raises:

Type Description
RuntimeSetupError

Executable resolution, validation, checksum, or bundled layout checks fail.

ValueError

The environment name is unsupported.

OSError

Filesystem/download operations fail; other network or archive exceptions can also propagate without runtime-specific wrapping.

Example
from femora import runtime
info = runtime.setup("local", executable="path/to/OpenSees")
print(info.executable, info.version)
Warning

Use a dedicated Colab installation directory. Installation or reinstallation can replace that directory and all its contents. The checksum checks consistency with the published bundle, not the trust of an arbitrary release source. Femora must already be installed before this helper can be imported.

run

run(tcl_file: Union[str, Path], *, executable: Optional[Union[str, Path]] = None, cwd: Optional[Union[str, Path]] = None, show_output: bool = False) -> subprocess.CompletedProcess[str]

Invoke one exported Tcl model and wait for the solver to finish.

Femora progress records are rendered as tqdm bars. OpenSees warnings, errors, and failed-step diagnostics are printed immediately. Set show_output=True to also display ordinary solver output.

Parameters:

Name Type Description Default
tcl_file str | Path

Existing exported Tcl file, resolved relative to the caller's current directory, independently of cwd.

required
executable str | Path | None

Solver file path. When omitted, uses FEMORA_OPENSEES, then PATH discovery. No startup probe is performed.

None
cwd str | Path | None

Existing solver working directory, resolved relative to the caller's directory. Defaults to the script's parent. Does not change how tcl_file itself is resolved or create a folder.

None
show_output bool

Display ordinary solver lines as well as diagnostics. Managed progress records are handled as progress bars.

False

Returns:

Name Type Description
completed CompletedProcess[str]

Successful command, return code, and combined stdout/stderr text in stdout. stderr is None.

Raises:

Type Description
FileNotFoundError

The resolved Tcl file does not exist.

RuntimeSetupError

No executable file can be resolved.

RuntimeExecutionError

The process cannot start, exits nonzero, or emits a managed FEMORA_PROGRESS error record.

Example

After setup() and model export:

from femora import runtime
def execute_exported_model(script, executable):
    completed = runtime.run(script, executable=executable, show_output=True)
    return completed.stdout
Note

No task workspace, manifest, or log file is created automatically. Relative Tcl file operations use the solver's working directory. All captured output remains in memory on success; write completed.stdout to a file explicitly if needed. On failure the exception message includes a summary and up to 20 trailing lines, not an attached CompletedProcess or RunResult.

Diagnostic text alone does not cause failure. A zero exit code without managed error records cannot detect every possible Tcl or numerical failure. Inspect convergence and response data independently. This helper does not construct an MPI launch command, submit a job, retry, or roll back files; use Jobs for allocation-aware task launching.