Note
Click here to download the full example code
Usage of the model-versus-data code verification tool on a Finite-Element (Abaqus) model¶
Check an Abaqus cantilever beam model versus a reference dataset with the 'CodeVerificationAgainstData' tool.
from __future__ import annotations
import logging
from gemseo.utils.directory_creator import DirectoryNamingMethod
from vimseo import EXAMPLE_RUNS_DIR
from vimseo.api import activate_logger
from vimseo.api import create_model
from vimseo.core.model_settings import IntegratedModelSettings
from vimseo.tools.verification.verification_vs_data import CodeVerificationAgainstData
We first define the logger level:
activate_logger(level=logging.INFO)
Then we create the model to verify:
model_name = "BendingTestAnalytical"
load_case = "Cantilever"
model = create_model(
model_name,
load_case,
model_options=IntegratedModelSettings(
directory_archive_root=EXAMPLE_RUNS_DIR / "archive/verification_vs_data",
directory_scratch_root=EXAMPLE_RUNS_DIR / "scratch/verification_vs_data",
cache_file_path=EXAMPLE_RUNS_DIR
/ f"caches/verification_vs_data/{model_name}_{load_case}_cache.hdf",
),
)
Out:
C:\Users\sebastien.bocquet\Dev\vd017\.tox\doc\Lib\site-packages\genson\schema\strategies\base.py:42: UserWarning:
Schema incompatible. Keyword 'description' has conflicting values ('Value of the reaction forces at the imposed displacement location' vs. ''). Using 'Value of the reaction forces at the imposed displacement location'
We also need reference data. A mapping of variable names to values is enough:
the tool reads the grammars of the model to tell its inputs from its outputs,
so the roles do not have to be declared. The same data read from a csv file
with pandas.read_csv could be passed directly as well.
reference_data = {
"height": [10.0, 15.0],
"width": [10.0, 10.0],
"maximum_dplt": [-4.0, -6.0],
"reaction_forces": [-12.0, -40.0],
}
All inputs to the verification are now available. We create the verification tool we are interested in.
verificator = CodeVerificationAgainstData(
directory_naming_method=DirectoryNamingMethod.NUMBERED,
working_directory="CodeVerificationAgainstData_results",
)
# The options can be modified.
# Alternatively, options can be passed as keyword arguments to
# ``CodeVerificationAgainstModelFromParameterSpace()`` constructor.
verificator.options["metric_names"] = [
"SquaredErrorMetric",
"RelativeErrorMetric",
"AbsoluteErrorMetric",
]
verificator.execute(
model=model,
reference_data=reference_data,
output_names=["maximum_dplt", "reaction_forces"],
description={
"title": "Verification of a cantilever analytic beam for a variation of beam height.",
"element_wise": ["Small height value", "High height value"],
},
)
Out:
INFO - 09:44:06: Working directory is C:\Users\sebastien.bocquet\Dev\vd017\docs\runnable_examples\03_verification_vs_data\CodeVerificationAgainstData_results
INFO - 09:44:06: Working directory is C:\Users\sebastien.bocquet\Dev\vd017\docs\runnable_examples\03_verification_vs_data\CodeVerificationAgainstData_results\CustomDOETool
INFO - 09:44:06: Working directory is C:\Users\sebastien.bocquet\Dev\vd017\docs\runnable_examples\03_verification_vs_data\CodeVerificationAgainstData_results\CustomDOETool
INFO - 09:44:06: *** Start DOEScenario execution ***
INFO - 09:44:06: DOEScenario
INFO - 09:44:06: Disciplines: Model BendingTestAnalytical: An analytical model for the bending of a parallelepipedic beam
INFO - 09:44:06:
INFO - 09:44:06: Load case:
INFO - 09:44:06: Load case Cantilever: A cantilever load case.
INFO - 09:44:06: Domain: Beam
INFO - 09:44:06:
INFO - 09:44:06: Boundary condition variables: imposed_dplt, relative_dplt_location
INFO - 09:44:06:
INFO - 09:44:06: Default values:
INFO - 09:44:06:
INFO - 09:44:06: Default geometrical variables:
INFO - 09:44:06: height = [40.0]
INFO - 09:44:06: length = [600.0]
INFO - 09:44:06: width = [30.0]
INFO - 09:44:06:
INFO - 09:44:06: Default boundary conditions variables:
INFO - 09:44:06: imposed_dplt = [-5.0]
INFO - 09:44:06: relative_dplt_location = [1.0]
INFO - 09:44:06:
INFO - 09:44:06: Default material variables:
INFO - 09:44:06: nu_p = [0.3]
INFO - 09:44:06: young_modulus = [210000.0]
INFO - 09:44:06:
INFO - 09:44:06: Model inputs: height, imposed_dplt, length, nu_p, relative_dplt_location, width, young_modulus
INFO - 09:44:06: Model outputs: cpu_time, date, description, directory_archive_job, directory_archive_root, directory_scratch_job, directory_scratch_root, dplt, dplt_at_force_location, dplt_grid, error_code, job_name, load_case, location_max_dplt, machine, maximum_dplt, model, moment, moment_grid, n_cpus, persistent_result_files, reaction_forces, user, vims_git_version
INFO - 09:44:06: MDO formulation: DisciplinaryOpt
INFO - 09:44:06: Optimization problem:
INFO - 09:44:06: minimize maximum_dplt(height, width)
INFO - 09:44:06: with respect to height, width
INFO - 09:44:06: over the design space:
INFO - 09:44:06: +--------+-------------+-------+-------------+-------+
INFO - 09:44:06: | Name | Lower bound | Value | Upper bound | Type |
INFO - 09:44:06: +--------+-------------+-------+-------------+-------+
INFO - 09:44:06: | height | -inf | None | inf | float |
INFO - 09:44:06: | width | -inf | None | inf | float |
INFO - 09:44:06: +--------+-------------+-------+-------------+-------+
INFO - 09:44:06: Solving optimization problem with algorithm CustomDOE:
INFO - 09:44:06: Current archive directory is C:\Users\sebastien.bocquet\Dev\vd017\docs\runnable_examples\model_runs\archive\verification_vs_data\BendingTestAnalytical\Cantilever\1.
INFO - 09:44:06: 50%|█████ | 1/2 [00:00<00:00, 11.01 it/sec, feas=True, obj=-5]
INFO - 09:44:06: Current archive directory is C:\Users\sebastien.bocquet\Dev\vd017\docs\runnable_examples\model_runs\archive\verification_vs_data\BendingTestAnalytical\Cantilever\2.
INFO - 09:44:06: 100%|██████████| 2/2 [00:00<00:00, 14.32 it/sec, feas=True, obj=-5]
INFO - 09:44:06: Optimization result:
INFO - 09:44:06: Optimizer info:
INFO - 09:44:06: Status: None
INFO - 09:44:06: Message: None
INFO - 09:44:06: Solution:
INFO - 09:44:06: Objective: -4.999999999999999
INFO - 09:44:06: Design space:
INFO - 09:44:06: +--------+-------------+-------+-------------+-------+
INFO - 09:44:06: | Name | Lower bound | Value | Upper bound | Type |
INFO - 09:44:06: +--------+-------------+-------+-------------+-------+
INFO - 09:44:06: | height | -inf | 10 | inf | float |
INFO - 09:44:06: | width | -inf | 10 | inf | float |
INFO - 09:44:06: +--------+-------------+-------+-------------+-------+
INFO - 09:44:06: *** End DOEScenario execution ***
VerificationResult(metadata=ToolResultMetadata(generic={'datetime': '28-10-2026_09-44-06', 'version': '0.1.8.dev0+g5ba602a7e.d20261028'}, misc={}, settings={'input_names': [], 'output_names': ['maximum_dplt', 'reaction_forces'], 'metric_names': ['SquaredErrorMetric', 'RelativeErrorMetric', 'AbsoluteErrorMetric'], 'description': {'title': 'Verification of a cantilever analytic beam for a variation of beam height.', 'element_wise': ['Small height value', 'High height value']}}, report={}, model=ModelDescription(name='BendingTestAnalytical', summary=' An analytical model for the bending of a parallelepipedic beam', load_case=Beam_Cantilever(name='Cantilever', domain='Beam', summary='A cantilever load case.', bc_variable_names=['imposed_dplt', 'relative_dplt_location'], load=Load(direction='', sign='', type='')), dataflow={'model_inputs': ['length', 'width', 'height', 'imposed_dplt', 'relative_dplt_location', 'young_modulus', 'nu_p'], 'model_outputs': ['reaction_forces', 'moment', 'moment_grid', 'dplt', 'dplt_grid', 'maximum_dplt', 'location_max_dplt', 'dplt_at_force_location', 'model', 'load_case', 'error_code', 'description', 'job_name', 'persistent_result_files', 'n_cpus', 'date', 'cpu_time', 'user', 'machine', 'vims_git_version', 'directory_archive_root', 'directory_archive_job', 'directory_scratch_root', 'directory_scratch_job'], 'PreBendingTestAnalytical_Cantilever': {'inputs': ['length', 'width', 'height', 'imposed_dplt', 'relative_dplt_location', 'young_modulus', 'nu_p'], 'outputs': ['imposed_dplt_location', 'quadratic_moment', 'reaction_forces', 'moment', 'moment_grid', 'solver', 'boundary']}, 'RunBendingTestAnalytical': {'inputs': ['solver', 'boundary', 'moment', 'moment_grid', 'young_modulus', 'quadratic_moment', 'nu_p'], 'outputs': ['dplt', 'dplt_grid']}, 'PostBendingTestAnalytical_Cantilever': {'inputs': ['dplt', 'dplt_grid', 'moment', 'moment_grid', 'imposed_dplt_location', 'reaction_forces'], 'outputs': ['reaction_forces', 'maximum_dplt', 'dplt_grid', 'location_max_dplt', 'dplt', 'moment', 'moment_grid', 'dplt_at_force_location']}, 'subroutine_names': []}, default_inputs={<InputGroupNames.NUMERICAL_VARS: 'numerical variables'>: {}, <InputGroupNames.BC_VARS: 'boundary conditions variables'>: {'imposed_dplt': [-5.0], 'relative_dplt_location': [1.0]}, <InputGroupNames.GEOMETRICAL_VARS: 'geometrical variables'>: {'length': [600.0], 'width': [30.0], 'height': [40.0]}, <InputGroupNames.MATERIAL_VARS: 'material variables'>: {'young_modulus': [210000.0], 'nu_p': [0.3]}}, verbose=False)), simulation_and_reference=GROUP inputs outputs ... Reference
VARIABLE height width cpu_time ... reaction_forces maximum_dplt reaction_forces
COMPONENT 0 0 0 ... 0 0 0
0 10.0 10.0 0.027292 ... -12.152778 -4.0 -12.0
1 15.0 10.0 0.002010 ... -41.015625 -6.0 -40.0
[2 rows x 7 columns], element_wise_metrics=GROUP SquaredErrorMetric ... inputs
VARIABLE maximum_dplt reaction_forces ... height width
COMPONENT 0 0 ... 0 0
0 1.0 0.023341 ... 10.0 10.0
1 1.0 1.031494 ... 15.0 10.0
[2 rows x 8 columns], integrated_metrics={'SquaredErrorMetric': {'maximum_dplt': np.float64(1.0000000000000009), 'reaction_forces': np.float64(0.5274175950038581)}, 'RelativeErrorMetric': {'maximum_dplt': np.float64(0.20833333328819448), 'reaction_forces': np.float64(0.019061053239892913)}, 'AbsoluteErrorMetric': {'maximum_dplt': np.float64(1.0000000000000004), 'reaction_forces': np.float64(0.5842013888888893)}}, description={'title': 'Verification of a cantilever analytic beam for a variation of beam height.', 'element_wise': ['Small height value', 'High height value']})
The result contains the error metrics:
verificator.result.integrated_metrics
Out:
{'SquaredErrorMetric': {'maximum_dplt': np.float64(1.0000000000000009), 'reaction_forces': np.float64(0.5274175950038581)}, 'RelativeErrorMetric': {'maximum_dplt': np.float64(0.20833333328819448), 'reaction_forces': np.float64(0.019061053239892913)}, 'AbsoluteErrorMetric': {'maximum_dplt': np.float64(1.0000000000000004), 'reaction_forces': np.float64(0.5842013888888893)}}
And saved on disk, together with its metadata:
verificator.save_results()
Out:
INFO - 09:44:07: Saving result to C:\Users\sebastien.bocquet\Dev\vd017\docs\runnable_examples\03_verification_vs_data\CodeVerificationAgainstData_results\CodeVerificationAgainstData_result.hdf5
INFO - 09:44:07: Saving result to C:\Users\sebastien.bocquet\Dev\vd017\docs\runnable_examples\03_verification_vs_data\CodeVerificationAgainstData_results\CustomDOETool\CustomDOETool_result.hdf5
The saved results can be loaded in a dedicated dashboard to be explored.
The dashboard is opened by typing dashboard_verification in a terminal,
and selecting the tab Comparison case.
The results can also be plotted from the Python API. It shows the scatter matrix of the inputs:
figures = verificator.plot_results(
verificator.result,
"RelativeErrorMetric",
"reaction_forces",
save=False,
show=True,
directory_path=verificator.working_directory,
)

Out:
C:\Users\sebastien.bocquet\Dev\vd017\.tox\doc\Lib\site-packages\pandas\plotting\_matplotlib\misc.py:100: UserWarning:
Attempting to set identical low and high xlims makes transformation singular; automatically expanding.
C:\Users\sebastien.bocquet\Dev\vd017\.tox\doc\Lib\site-packages\pandas\plotting\_matplotlib\misc.py:101: UserWarning:
Attempting to set identical low and high ylims makes transformation singular; automatically expanding.
C:\Users\sebastien.bocquet\Dev\vd017\.tox\doc\Lib\site-packages\pandas\plotting\_matplotlib\misc.py:91: UserWarning:
Attempting to set identical low and high xlims makes transformation singular; automatically expanding.
C:\Users\sebastien.bocquet\Dev\vd017\.tox\doc\Lib\site-packages\gemseo\utils\matplotlib_figure.py:126: UserWarning:
FigureCanvasAgg is non-interactive, and thus cannot be shown
INFO - 09:44:07: Working directory is C:\Users\sebastien.bocquet\Dev\vd017\docs\runnable_examples\03_verification_vs_data\CodeVerificationAgainstData_results
{'text/html': '<div> <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG"></script><script type="text/javascript">if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: "STIX-Web"}});}</script> <script type="text/javascript">window.PlotlyConfig = {MathJaxConfig: \'local\'};</script>\n <script charset="utf-8" src="https://cdn.plot.ly/plotly-2.35.0.min.js"></script> <div id="cc2165c1-5201-4be7-8619-6e08b3ccd6c7" class="plotly-graph-div" style="height:525px; width:100%;"></div> <script type="text/javascript"> window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById("cc2165c1-5201-4be7-8619-6e08b3ccd6c7")) { Plotly.newPlot( "cc2165c1-5201-4be7-8619-6e08b3ccd6c7", [{"alignmentgroup":"True","bingroup":"x","hovertemplate":"reaction_forces=%{x}\\u003cbr\\u003ecount=%{y}\\u003cextra\\u003e\\u003c\\u002fextra\\u003e","legendgroup":"","marker":{"color":"#000001","pattern":{"shape":""}},"name":"","offsetgroup":"","orientation":"v","showlegend":false,"x":[0.01273148148042059,0.025390624999365237],"xaxis":"x","yaxis":"y","type":"histogram"}], {"template":{"data":{"candlestick":[{"decreasing":{"line":{"color":"#000033"}},"increasing":{"line":{"color":"#000032"}},"type":"candlestick"}],"contourcarpet":[{"colorscale":[[0.0,"#000011"],[0.1111111111111111,"#000012"],[0.2222222222222222,"#000013"],[0.3333333333333333,"#000014"],[0.4444444444444444,"#000015"],[0.5555555555555556,"#000016"],[0.6666666666666666,"#000017"],[0.7777777777777778,"#000018"],[0.8888888888888888,"#000019"],[1.0,"#000020"]],"type":"contourcarpet"}],"contour":[{"colorscale":[[0.0,"#000011"],[0.1111111111111111,"#000012"],[0.2222222222222222,"#000013"],[0.3333333333333333,"#000014"],[0.4444444444444444,"#000015"],[0.5555555555555556,"#000016"],[0.6666666666666666,"#000017"],[0.7777777777777778,"#000018"],[0.8888888888888888,"#000019"],[1.0,"#000020"]],"type":"contour"}],"heatmap":[{"colorscale":[[0.0,"#000011"],[0.1111111111111111,"#000012"],[0.2222222222222222,"#000013"],[0.3333333333333333,"#000014"],[0.4444444444444444,"#000015"],[0.5555555555555556,"#000016"],[0.6666666666666666,"#000017"],[0.7777777777777778,"#000018"],[0.8888888888888888,"#000019"],[1.0,"#000020"]],"type":"heatmap"}],"histogram2d":[{"colorscale":[[0.0,"#000011"],[0.1111111111111111,"#000012"],[0.2222222222222222,"#000013"],[0.3333333333333333,"#000014"],[0.4444444444444444,"#000015"],[0.5555555555555556,"#000016"],[0.6666666666666666,"#000017"],[0.7777777777777778,"#000018"],[0.8888888888888888,"#000019"],[1.0,"#000020"]],"type":"histogram2d"}],"icicle":[{"textfont":{"color":"white"},"type":"icicle"}],"sankey":[{"textfont":{"color":"#000036"},"type":"sankey"}],"scatter":[{"marker":{"line":{"width":0}},"type":"scatter"}],"table":[{"cells":{"fill":{"color":"#000038"},"font":{"color":"#000037"},"line":{"color":"#000039"}},"header":{"fill":{"color":"#000040"},"font":{"color":"#000036"},"line":{"color":"#000039"}},"type":"table"}],"waterfall":[{"connector":{"line":{"color":"#000036","width":2}},"decreasing":{"marker":{"color":"#000033"}},"increasing":{"marker":{"color":"#000032"}},"totals":{"marker":{"color":"#000034"}},"type":"waterfall"}]},"layout":{"coloraxis":{"colorscale":[[0.0,"#000011"],[0.1111111111111111,"#000012"],[0.2222222222222222,"#000013"],[0.3333333333333333,"#000014"],[0.4444444444444444,"#000015"],[0.5555555555555556,"#000016"],[0.6666666666666666,"#000017"],[0.7777777777777778,"#000018"],[0.8888888888888888,"#000019"],[1.0,"#000020"]]},"colorscale":{"diverging":[[0.0,"#000021"],[0.1,"#000022"],[0.2,"#000023"],[0.3,"#000024"],[0.4,"#000025"],[0.5,"#000026"],[0.6,"#000027"],[0.7,"#000028"],[0.8,"#000029"],[0.9,"#000030"],[1.0,"#000031"]],"sequential":[[0.0,"#000011"],[0.1111111111111111,"#000012"],[0.2222222222222222,"#000013"],[0.3333333333333333,"#000014"],[0.4444444444444444,"#000015"],[0.5555555555555556,"#000016"],[0.6666666666666666,"#000017"],[0.7777777777777778,"#000018"],[0.8888888888888888,"#000019"],[1.0,"#000020"]],"sequentialminus":[[0.0,"#000011"],[0.1111111111111111,"#000012"],[0.2222222222222222,"#000013"],[0.3333333333333333,"#000014"],[0.4444444444444444,"#000015"],[0.5555555555555556,"#000016"],[0.6666666666666666,"#000017"],[0.7777777777777778,"#000018"],[0.8888888888888888,"#000019"],[1.0,"#000020"]]},"colorway":["#000001","#000002","#000003","#000004","#000005","#000006","#000007","#000008","#000009","#000010"]}},"xaxis":{"anchor":"y","domain":[0.0,1.0],"title":{"text":"reaction_forces"}},"yaxis":{"anchor":"x","domain":[0.0,1.0],"title":{"text":"count"}},"legend":{"tracegroupgap":0},"margin":{"t":60},"barmode":"relative"}, {"responsive": true} ) }; </script> </div>'}
and an histogram of the errors:
figures["error_metric_histogram"]
Total running time of the script: ( 0 minutes 0.878 seconds)
Download Python source code: plot_bending_test_vs_data.py