diff --git a/.ci_support/run_docker_linux.sh b/.ci_support/run_docker_linux.sh index 30324bb..de56ed6 100755 --- a/.ci_support/run_docker_linux.sh +++ b/.ci_support/run_docker_linux.sh @@ -7,7 +7,7 @@ aurman -S python-sphinx-renku-theme python-sphinx_rtd_theme --noconfirm --noedit cp -r /io/* /tmp cd /tmp -pip install . --user --break-system-packages +pip install . --user --break-system-packages --no-deps ~/.local/bin/mo2fmu -h ~/.local/bin/mo2fmu ./otfmi/example/file/deviation.mo ./otfmi/example/file/fmu/linux-x86_64/deviation.fmu pythonfmu build --file ./otfmi/example/file/DeviationSlave.py --dest ./otfmi/example/file/fmu/linux-x86_64 diff --git a/doc/application/plot_cantilever_beam.py b/doc/application/plot_cantilever_beam.py index f64a7ab..1d912b7 100644 --- a/doc/application/plot_cantilever_beam.py +++ b/doc/application/plot_cantilever_beam.py @@ -29,7 +29,7 @@ import openturns as ot import otfmi import otfmi.example.utility -from openturns.viewer import View +import openturns.viewer as otv path_fmu = otfmi.example.utility.get_path_fmu("deviation") @@ -41,7 +41,7 @@ # We test the function wrapping the deviation model on a point: point = ot.Point([3e7, 2e4, 255, 350]) model_evaluation = model_fmu(point) -print("Running the FMU: deviation = {}".format(model_evaluation)) +print(f"Running the FMU: deviation = {model_evaluation}") # %% @@ -112,15 +112,18 @@ # Draw the distribution of threshold excedance probability: monte_carlo_result = algo.getResult() probabilityDistribution = monte_carlo_result.getProbabilityDistribution() -graph = View(probabilityDistribution.drawPDF()) +graph = otv.View(probabilityDistribution.drawPDF()) # %% # Get the probability with which the beam deviation exceeds 30 cm: probability = monte_carlo_result.getProbabilityEstimate() -print("Threshold excedance probability: {}".format(probability)) +print(f"Threshold excedance probability: {probability}") # %% # Given the uncertainties on the load applied and the beam mechanical # parameters, the beam bending has a probability of 0.01 to exceed 30 cm. # Is this probability low or not ? It depends on your context 🙂 + +# %% +otv.View.ShowAll() diff --git a/doc/application/plot_metamodel.py b/doc/application/plot_metamodel.py index 7f39744..08f72d6 100644 --- a/doc/application/plot_metamodel.py +++ b/doc/application/plot_metamodel.py @@ -47,7 +47,7 @@ import otfmi.example.utility import openturns as ot -import openturns.viewer as viewer +import openturns.viewer as otv path_fmu = otfmi.example.utility.get_path_fmu("epid") mesh = ot.RegularGrid(0.0, 0.05, 20) @@ -75,12 +75,11 @@ graph.setTitle("FMU simulations") graph.setXTitle("Time") graph.setYTitle("Number of infected") -graph.setLegends(["{:.3f}".format(line[0]) for line in inputSample]) -view = viewer.View(graph, legend_kw={"title": "infection rate", "loc": "upper left"}) -view.ShowAll() +graph.setLegends([f"{line[0]:.3f}" for line in inputSample[:15]] + ["_"] * 15) +view = otv.View(graph, legend_kw={"title": "infection rate", "loc": "upper left"}) # %% -# We define a function to visualize the upcoming Karhunen-Loevem modes. +# We define a function to visualize the upcoming Karhunen-Loeve modes. def drawKL(scaledKL, KLev, mesh, title="Scaled KL modes"): @@ -121,15 +120,14 @@ def drawKL(scaledKL, KLev, mesh, title="Scaled KL modes"): phi_Y = resultKL.getScaledModesAsProcessSample() lambda_Y = resultKL.getEigenvalues() graph_modes_Y, graph_ev_Y = drawKL(phi_Y, lambda_Y, mesh, "Y") -view = viewer.View(graph_modes_Y) -view.ShowAll() +view = otv.View(graph_modes_Y) # %% # Now that Karhunen-Loeve algorithm is trained, we can project them # in the smaller-dimension space: projectionSample = resultKL.project(outputFMUSample) n_mode = projectionSample.getDimension() -print("Karhunen-Loeve projection is dimension {}".format(n_mode)) +print(f"Karhunen-Loeve projection in dimension {n_mode}") # %% # We keep on following our road map, by metamodeling the projection @@ -186,20 +184,20 @@ def globalMetamodel(sample): for graph in [graph1, graph2]: graph.setXTitle("Time") graph.setYTitle("Number of infected") - graph.setLegends(["{:.3f}".format(line[0]) for line in inputSample]) + graph.setLegends([f"{line[0]:.3f}" for line in inputSample[:10]]) gridLayout.setGraph(0, 0, graph1) gridLayout.setGraph(0, 1, graph2) -view = viewer.View( +view = otv.View( gridLayout, legend_kw={"title": "infection rate", "loc": "upper left"} ) -view.ShowAll() # %% # We validate the pertinence of Karhunen-Loeve decomposition: validationKL = ot.KarhunenLoeveValidation(outputFMUTestSample, resultKL) graph = validationKL.computeResidualMean().draw() +graph.setYTitle("infected residual mean") ot.Show(graph) # %% @@ -237,3 +235,6 @@ def globalMetamodel(sample): # - `estimate a failure probability `_, # # etc. + +# %% +otv.View.ShowAll() diff --git a/doc/example/dynamic/plot_dyn_init.py b/doc/example/dynamic/plot_dyn_init.py index 515632b..760f040 100644 --- a/doc/example/dynamic/plot_dyn_init.py +++ b/doc/example/dynamic/plot_dyn_init.py @@ -91,6 +91,6 @@ graph.setTitle("") graph.setXTitle("FMU simulation time (s)") graph.setYTitle("Number of infected") -graph.setLegends(["{:.4f}".format(line[0]) for line in inputSample]) +graph.setLegends([f"{line[0]:.4f}" for line in inputSample]) view = viewer.View(graph, legend_kw={"title": "infection rate", "loc": "upper left"}) view.ShowAll() diff --git a/doc/example/low_level/plot_explore.py b/doc/example/low_level/plot_explore.py index ca8d5b7..bacb03a 100644 --- a/doc/example/low_level/plot_explore.py +++ b/doc/example/low_level/plot_explore.py @@ -30,7 +30,7 @@ for name in list_name: causality = otfmi.fmi.get_causality_str(model, name) - print("{}: {}".format(name, causality)) + print(f"{name}: {causality}") # %% # | Yet the variables type is not known: real, integer, boolean, string? @@ -38,7 +38,7 @@ for name in list_name: typ = model.get_variable_data_type(name) - print("{}: {}".format(name, typ)) + print(f"{name}: {typ}") # %% # | The type `0` corresponds to `Real` (aka "float") variables. diff --git a/doc/example/static/plot_basics.py b/doc/example/static/plot_basics.py index a2ddaa0..3618dc6 100644 --- a/doc/example/static/plot_basics.py +++ b/doc/example/static/plot_basics.py @@ -28,7 +28,7 @@ # Simulate the FMU on a point: inputPoint = ot.Point([3.0e7, 30000, 200, 400]) outputPoint = function(inputPoint) -print("y = {}".format(outputPoint)) +print(f"y = {outputPoint}") # %% # Simulate the FMU on a sample: