# How to run multiple analyses automatically?

**URL:** <https://persalys.discourse.group/t/how-to-run-multiple-analyses-automatically/144>\
**Category:** Advanced use\
**Created:** [June 11, 2024, 1:34pm UTC](https://persalys.discourse.group/t/how-to-run-multiple-analyses-automatically/144 "2024-06-11T13:34:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dumas](https://yyz2.discourse-cdn.com/free1/user_avatar/persalys.discourse.group/dumas/32/5_2.png) [@dumas](https://persalys.discourse.group/u/dumas)\
**Post date:** [June 11, 2024, 1:34pm UTC](https://persalys.discourse.group/t/how-to-run-multiple-analyses-automatically/144/1 "2024-06-11T13:34:45Z")

</div>

Hello,

Here is an example describing how to use the Python API of Persalys in order to automatically launch analyses.

One may have several analyses to launch and each analysis is time consuming so it could be nice to launch everything overnight. The problem is that Persalys does not have the possibility to define a list of analysis to be executed one after the other.

However it is possible to use the Python API of Persalys to get the current available analyses of a study and then run the desired analysis.

In the following minimal example, several analyses are defined but not evaluated:

 ![image](https://global.discourse-cdn.com/free1/uploads/persalys/original/1X/8baae0a3dcbd3f9dbe980071aa345966875ed2ff.png)

The following code can be copied in the Persalys console to launch automatically all selected analyses (by names):

```python
import persalys
# get the first study opened in Persalys (to be modified if several studies exist in Persalys)
study = persalys.Study.GetInstances()[0]
# Name of the analyses (must match the names in Persalys)
analysis_name_list = ['optimisation_0', 'screening_0', 'sensitivity_0', 'optimisation_1']
# launch the analyses in a for loop
for analysis_name in analysis_name_list:
    analysis = study.getAnalysisByName(analysis_name)
    analysis.run()

```

 ![image](https://global.discourse-cdn.com/free1/uploads/persalys/original/1X/e68e00696fd599e052270f33b257c3570fa6d374.png)

I hope this could be useful in your study !

Regards,  
Antoine

---

<div class="post-metadata">

**Author:** ![Flore](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@Flore](https://persalys.discourse.group/u/Flore)\
**Post date:** [June 11, 2024, 1:54pm UTC](https://persalys.discourse.group/t/how-to-run-multiple-analyses-automatically/144/2 "2024-06-11T13:54:17Z")

</div>

Great Antoine!  
And if one of these analysis is already done, what happens when command “analysis.run()” is executed ?

---

<div class="post-metadata">

**Author:** ![dumas](https://yyz2.discourse-cdn.com/free1/user_avatar/persalys.discourse.group/dumas/32/5_2.png) [@dumas](https://persalys.discourse.group/u/dumas)\
**Post date:** [June 11, 2024, 2:01pm UTC](https://persalys.discourse.group/t/how-to-run-multiple-analyses-automatically/144/3 "2024-06-11T14:01:30Z")

</div>

If the analysis is already done, it will be relaunched but it is possible to check if the analysis has been already launched using this command:

```python
analysis.hasValidResult()

```

It will return True if results are already available, False otherwise. So it is simple to add a condition before running the analysis.
