# Changing step size

**URL:** https://discourse.kitware.com/t/changing-step-size/1068
**Category:** Pulse Physiology Engine
**Created:** [July 21, 2023, 4:53pm UTC](https://discourse.kitware.com/t/changing-step-size/1068 "2023-07-21T16:53:49Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![bob.marinier](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/b/7ab992/32.png) [@bob.marinier](https://discourse.kitware.com/u/bob.marinier)
#### Post date: [July 21, 2023, 4:53pm UTC](https://discourse.kitware.com/t/changing-step-size/1068/1 "2023-07-21T16:53:50Z")

</div>

Internally, Pulse uses a 0.02s step size. I’m interested in increasing this to see if we can make pulse run faster. I realize this will degrade the accuracy, but it may be that there is a sweet spot for our purposes where the accuracy is good enough but pulse runs significantly faster.

In looking through the code, I see the step size is set in PulseConfiguration.cpp here: [https://gitlab.kitware.com/physiology/engine/-/blob/stable/src/cpp/engine/PulseConfiguration.cpp#L477](https://gitlab.kitware.com/physiology/engine/-/blob/stable/src/cpp/engine/PulseConfiguration.cpp#L477)

While the SEScalarTime object that holds the step size is mutable, I don’t see a way to access it to change it, or to set a different default. Is there a way to do this without rebuilding? (I don’t mind rebuilding, but it’s nice not to have to.)

In that same place I also see that m\_AllowDynamicTimeStep is set to Off. What does this flag do and is that something else I should explore to increase performance?

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [July 21, 2023, 6:27pm UTC](https://discourse.kitware.com/t/changing-step-size/1068/2 "2023-07-21T18:27:25Z")

</div>

We had a previous project where we analyzed and identified several key updates we could do in Pulse to speed up the engine.

Increasing the time step was one of them.  
I updated the engine to ensure all of our models calculate using the specified time step value

So you can set the time step you want in [a configuration object](https://gitlab.kitware.com/physiology/engine/-/blob/stable/src/cpp/cdm/PhysiologyEngine.h#L150), [or scenario](https://gitlab.kitware.com/physiology/engine/-/blob/stable/data/human/adult/scenarios/patient/BasicStandard.json), and Pulse will execute each time step at that time interval. In our study, we found that, if you are ok with not getting high fidelity waveforms, you can run with a time step at most of 0.06s, anything above that gets pretty unreliable. I think 0.04s was pretty ok.

To enable the AllowDynamicTimeStep, you can find that flag in your state json file, or you can add it to that json in the configuration object, which would look similar to the json in the BasicStandard file linked above.

Then, what that does, is any time value you provide to [this AdvanceModelTime method](https://gitlab.kitware.com/physiology/engine/-/blob/stable/src/cpp/cdm/PhysiologyEngine.h#L205), that time is the time step it will use, so don’t ever advance with anything higher than 0.06s. Subsequent [AdvanceModelTime](https://gitlab.kitware.com/physiology/engine/-/blob/stable/src/cpp/cdm/PhysiologyEngine.h#L194) calls will still use that time step. I currently don’t have a way for you to easily change that as you are running outside of C++. I think the best you could do is run 0.06s steps when the patient is stableish, then 0.02 when lots of trauma stuff is going on, then once somebody stabilizing/treats the patient, kick back up to 0.06 steps.

Again, there were several other improvments we could implement to quicken how long Pulse takes to calculate each time step besides changing the time step. But only the time step change is close to being usable, but that still needs some interface additions to really be easy to use.

Best you can do now is see if you can experiment with with some scenarios and their time step and how that affects the results.

---

<div class="post-metadata">

### Author: ![bob.marinier](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/b/7ab992/32.png) [@bob.marinier](https://discourse.kitware.com/u/bob.marinier)
#### Post date: [July 21, 2023, 6:38pm UTC](https://discourse.kitware.com/t/changing-step-size/1068/3 "2023-07-21T18:38:04Z")

</div>

This is super helpful! It looks like I can’t set the configuration object from Java, although the project that wants to do this is actually using Python (it’s different than the one I usually work on) – is it available there? But setting it in the scenario is easy, so that’s good enough for our purposes. The dynamic stuff sounds interesting – if we want to try that, we can rebuild the C++ to turn it on.

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [July 21, 2023, 6:44pm UTC](https://discourse.kitware.com/t/changing-step-size/1068/4 "2023-07-21T18:44:07Z")

</div>

Not exposed for python either

You don’t need to rebuid pulse, there is a PulseConfiguration.json in your bin folder

You can also set the DynamicTimeStep there to turn it on

I believe that should also overwrite config values in your state as well… I think

---

<div class="post-metadata">

### Author: ![bob.marinier](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/b/7ab992/32.png) [@bob.marinier](https://discourse.kitware.com/u/bob.marinier)
#### Post date: [July 21, 2023, 6:54pm UTC](https://discourse.kitware.com/t/changing-step-size/1068/5 "2023-07-21T18:54:31Z")

</div>

We tried setting the configuration in a patient file and a state file like this:

```auto
"Configuration": {
    "TimeStep" : { "ScalarTime": { "Value": 0.02, "Unit": "s" } }
  },

```

But it doesn’t seem to work. But setting it in `PulseConfiguration.json` like this worked:

```auto
{
  "TimeStep" : { "ScalarTime": { "Value": 0.04, "Unit": "s" } }
}

```

Thanks!

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [July 21, 2023, 7:01pm UTC](https://discourse.kitware.com/t/changing-step-size/1068/6 "2023-07-21T19:01:56Z")

</div>

Great!

Yeah, configuration mod’ing support is there, but now well tested… or exposed

Glad you are able to get it doing!

---

<div class="post-metadata">

### Author: ![NucleusDev](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/n/ba8739/32.png) [@NucleusDev](https://discourse.kitware.com/u/NucleusDev)
#### Post date: [April 26, 2024, 7:01am UTC](https://discourse.kitware.com/t/changing-step-size/1068/7 "2024-04-26T07:01:36Z")

</div>

Hey,  
Is there a way to change this in the unreal plugin. Cant find the PulseConfiguration file mentioned above for the Unreal version

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [April 26, 2024, 2:56pm UTC](https://discourse.kitware.com/t/changing-step-size/1068/8 "2024-04-26T14:56:40Z")

</div>

Engine configuration is currently only supported for engine initialization, not if you load a state. We haven’t exposed a way to do this dynamically yet.
