# Measuring and saving runtime for GCMC

**URL:** <https://aiida.discourse.group/t/measuring-and-saving-runtime-for-gcmc/57>\
**Category:** General Usage\
**Created:** [July 27, 2023, 7:34am UTC](https://aiida.discourse.group/t/measuring-and-saving-runtime-for-gcmc/57 "2023-07-27T07:34:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vincentdufourdecieux](https://avatars.discourse-cdn.com/v4/letter/v/73ab20/32.png) [@vincentdufourdecieux](https://aiida.discourse.group/u/vincentdufourdecieux)\
**Post date:** [July 27, 2023, 7:34am UTC](https://aiida.discourse.group/t/measuring-and-saving-runtime-for-gcmc/57/1 "2023-07-27T07:34:27Z")

</div>

Hi everyone,

I am running adsorption isotherms with Aiida using RASPA, which means that I run several GCMC simulations one after the others. I would like to save the runtime of the whole process. How could I do that?

Thank you in advance for your help !  
Vincent

---

<div class="post-metadata">

**Author:** ![mbercx](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/mbercx/32/345_2.png) [@mbercx](https://aiida.discourse.group/u/mbercx)\
**Post date:** [July 27, 2023, 8:07am UTC](https://aiida.discourse.group/t/measuring-and-saving-runtime-for-gcmc/57/2 "2023-07-27T08:07:33Z")

</div>

Hi Vincent! 👋 For each calculation job, there is quite a bit of information on the scheduler (e.g. Slurm) job stored in the attributes of the node under the `last_job_info` key. For figuring out the time the job ran on the computer you can look at the `wallclock_time_seconds`:

```python
from aiida import orm, load_profile
load_profile()

calcjob = orm.load_node(2126815)
calcjob.attributes['last_job_info']['wallclock_time_seconds']

```

If you want to find the total time that all calculation jobs executed by a work chain, you can use the `called_descendants` attribute, for example:

```auto
workchain = orm.load_node(2125618)

total_walltime = 0

for calcjob in [
    process for process in workchain.called_descendants
    if isinstance(process, orm.CalcJobNode)
    ]:
    total_walltime += calcjob.attributes['last_job_info']['wallclock_time_seconds']

print(total_walltime)

```

If you’re interested in the amount of node hours, you can also look at the `num_machines` key in the `last_job_info` attribute.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![vincentdufourdecieux](https://avatars.discourse-cdn.com/v4/letter/v/73ab20/32.png) [@vincentdufourdecieux](https://aiida.discourse.group/u/vincentdufourdecieux)\
**Post date:** [July 27, 2023, 8:45am UTC](https://aiida.discourse.group/t/measuring-and-saving-runtime-for-gcmc/57/3 "2023-07-27T08:45:16Z")

</div>

Hi Marnik,

Great, thank you for your help and quick answer!  
I am a bit unclear how I know what is the node number (‘2125618’) for my case? I construct a builder and do ‘wc = aiida.engine.submit(builder)’, so how do I get the node from this ?

Thank you for you help!  
Vincent

---

<div class="post-metadata">

**Author:** ![mbercx](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/mbercx/32/345_2.png) [@mbercx](https://aiida.discourse.group/u/mbercx)\
**Post date:** [July 27, 2023, 9:00am UTC](https://aiida.discourse.group/t/measuring-and-saving-runtime-for-gcmc/57/4 "2023-07-27T09:00:15Z")

</div>

The node number is simply the PK. In your example the work chain node can be obtained using `wc.pk`. Of course the script above will only work for successfully completed work chains. It’s also possible the `total_walltime` line will throw a `KeyError` in case a calculation job failed.

---

<div class="post-metadata">

**Author:** ![yakutovicha](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/yakutovicha/32/18_2.png) [@yakutovicha](https://aiida.discourse.group/u/yakutovicha)\
**Post date:** [July 27, 2023, 1:00pm UTC](https://aiida.discourse.group/t/measuring-and-saving-runtime-for-gcmc/57/5 "2023-07-27T13:00:19Z")

</div>

Hey Vincent!

It is unclear whether you use the [RASPA/CP2K/Zeo++ workflows](https://github.com/lsmo-epfl/aiida-lsmo) we developed a while ago. Just to say, when we developed them, we took great care of saving CPU time by restarting from the previous runs. At this point, the workflows are pretty robust, I would say.

Please have a look at the following links:

- The [Isotherm work chain](https://github.com/lsmo-epfl/aiida-lsmo/blob/develop/aiida_lsmo/workchains/isotherm.py).
- The [documentation](https://aiida-lsmo.readthedocs.io/en/latest/workflows.html#isotherm-work-chain).
- The [AiiDAlab application](https://github.com/lsmo-epfl/aiidalab-epfl-lsmo), which provides you with GUI to run those simulations.
- [Paper](https://archive.materialscloud.org/record/2021.100) that has been published using the Isotherm work chain (and others)

Best,  
Sasha

---

<div class="post-metadata">

**Author:** ![vincentdufourdecieux](https://avatars.discourse-cdn.com/v4/letter/v/73ab20/32.png) [@vincentdufourdecieux](https://aiida.discourse.group/u/vincentdufourdecieux)\
**Post date:** [July 27, 2023, 1:39pm UTC](https://aiida.discourse.group/t/measuring-and-saving-runtime-for-gcmc/57/6 "2023-07-27T13:39:12Z")

</div>

Hi Sasha,

I am using the Isotherm work chain. I want to measure the computational time to compare it with other computational methods in terms of runtime.  
Thanks for your help !  
Vincent
