.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/RunModel/cluster_script_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_RunModel_cluster_script_example.py: Cluster Script Example for Third-party ====================================== .. GENERATED FROM PYTHON SOURCE LINES 8-16 In this case, we're just running a simple addition of random numbers, but the process is exactly the same for more complicated workflows. The pre- and post-processing is done through `model_script` and `output_script` respectively, while the computationally intensive portion of the workflow is launched in `cluster_script`. The example below provides a minimal framework from which more complex cases can be constructed. Import the necessary libraries .. GENERATED FROM PYTHON SOURCE LINES 19-27 .. code-block:: default from UQpy.sampling import LatinHypercubeSampling from UQpy.run_model.RunModel import RunModel from UQpy.run_model.model_execution.ThirdPartyModel import ThirdPartyModel from UQpy.distributions import Uniform import numpy as np import time import csv .. GENERATED FROM PYTHON SOURCE LINES 28-29 Define the distribution objects. .. GENERATED FROM PYTHON SOURCE LINES 32-36 .. code-block:: default var_names=["var_1", "var_2"] distributions = [Uniform(250.0, 40.0), Uniform(66.0, 24.0)] .. GENERATED FROM PYTHON SOURCE LINES 37-38 Draw the samples using Latin Hypercube Sampling. .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: default x_lhs = LatinHypercubeSampling(distributions, nsamples=64) .. GENERATED FROM PYTHON SOURCE LINES 45-46 Run the model. .. GENERATED FROM PYTHON SOURCE LINES 49-63 .. code-block:: default model = ThirdPartyModel(var_names=var_names, input_template='inputRealization.json', model_script='addition_run.py', output_script='process_addition_output.py', output_object_name='OutputProcessor', model_dir='AdditionRuns') t = time.time() modelRunner = RunModel(model=model, samples=x_lhs.samples, ntasks=1, cores_per_task=2, nodes=1, resume=False, run_type='CLUSTER', cluster_script='./run_script.sh') t_total = time.time() - t print("\nTotal time for all experiments:") print(t_total, "\n") .. GENERATED FROM PYTHON SOURCE LINES 64-65 Print model results--this is just for illustration .. GENERATED FROM PYTHON SOURCE LINES 68-79 .. code-block:: default for index, experiment in enumerate(modelRunner.qoi_list, 0): if len(experiment.qoi) != 0: for item in experiment.qoi: print("These are the random numbers for sample {}:".format(index)) for sample in x_lhs.samples[index]: print("{}\t".format(sample)) print("This is their sum:") for result in item: print("{}\t".format(result)) print() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_RunModel_cluster_script_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/SURGroup/UQpy/master?urlpath=lab/tree/notebooks/auto_examples/RunModel/cluster_script_example.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: cluster_script_example.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: cluster_script_example.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_