OneSimulation docs Website Free books Plans on Gumroad

Docs › Worked physics and service recipes › Shared cell for facade configurations

6.3 Shared cell for facade configurations

Use this cell for provider-selected configurations. The biophysics facades also accept a method-neutral problem with an explicit state. Validate first, then use the typed result fields shown in each recipe. The configurations in these examples assume the provider registry shipped with the inspected source.

import numpy as np
import matplotlib.pyplot as plt
import onesimulation_plot_theme as theme


def run_service(service, configuration, problem=None):
    args = (configuration,) if problem is None else (problem, configuration)
    issues = service.validate(*args)
    if issues:
        raise ValueError("\n".join(issues))
    return service.run(*args)


def service_figure(title, x, x_label, *series):
    theme.use_theme()
    fig, axes = plt.subplots(
        len(series),
        1,
        sharex=True,
        squeeze=False,
        figsize=(7.2, 1.3 * len(series) + 0.85),
        layout="constrained",
    )
    for ax, (label, values) in zip(axes[:, 0], series):
        y = np.asarray(values)
        assert y.ndim == 1 and y.shape == np.shape(x) and np.isfinite(y).all()
        ax.plot(x, y, ".-" if len(y) < 12 else "-", markersize=4)
        ax.set_ylabel(label)
        ax.grid(alpha=0.25)
    axes[-1, 0].set_xlabel(x_label)
    fig.suptitle(title, fontweight="bold")
    return fig