# File Formatting Bug in the task4 Workshop File

**URL:** <https://festim.discourse.group/t/file-formatting-bug-in-the-task4-workshop-file/25>\
**Category:** User Support\
**Created:** [December 22, 2023, 7:49pm UTC](https://festim.discourse.group/t/file-formatting-bug-in-the-task4-workshop-file/25 "2023-12-22T19:49:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ee-nn](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/ee-nn/32/6_2.png) [@ee-nn](https://festim.discourse.group/u/ee-nn)\
**Post date:** [December 22, 2023, 7:49pm UTC](https://festim.discourse.group/t/file-formatting-bug-in-the-task4-workshop-file/25/1 "2023-12-22T19:49:45Z")

</div>

I’m running version 1.1.1 of FESTIM, and it seems like some minor file formatting issues are still persisting in the code (see [here](https://github.com/festim-dev/FESTIM/issues/672) for the first issue). I discovered this on trying to run the task4 workshop notebook (found [here](https://github.com/festim-dev/FESTIM-workshop/blob/main/tasks/task4.ipynb)). When trying to plot the results of the simulation, only the concentartion t = 80,000s is plotted, which is the end of the simulation. (It’s colored green below because of the messed up legend assigment.)

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

This can be compared to the preview seen on the Github repo:

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

I checked the `mobile.txt` file and it only had one column of data in it for t = 80,000s, despite 3 different timestamps being specified in the `TXTExports()` method:

```auto
folder = "task4"

derived_quantities_with_barrier = F.DerivedQuantities()
derived_quantities_with_barrier.derived_quantities = [F.HydrogenFlux(surface=2)]

txt_exports = F.TXTExports(
    fields=['solute'],
    labels=['mobile'],
    times=[100, 17000, 8e5],
    folder=folder
    )

model_barrier.exports = [derived_quantities_with_barrier] + txt_exports.exports

```

It seems that the bug stems from `mobile.txt` being overwritten every time the `TXTExports()` method is specified to write data to the file.

Thanks in advance to whoever can help, hopefully it’s an easy fix!

---

<div class="post-metadata">

**Author:** ![remidm](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/remidm/32/4_2.png) [@remidm](https://festim.discourse.group/u/remidm)\
**Post date:** [December 22, 2023, 8:22pm UTC](https://festim.discourse.group/t/file-formatting-bug-in-the-task4-workshop-file/25/2 "2023-12-22T20:22:44Z")

</div>

Thanks @ee-nn for reporting this.

The workshop hasn’t been updated yet for FESTIM\>1.0 and so a few things don’t work anymore. This is something we need to do!

This is not a bug, it’s a change in behaviour.  
Before 1.0, the `TXTExport` class used to modify the stepsize in order to pass through the correct times (eg. if the current time is 10, the current stepsize is 5, and the next export time is 11, then the stepsize is cutback to 1).

Instead, we introduced milestones in 1.0. Milestones can be defined in `Settings` in order to make sure the simulation hits these times.

Consider doing the following:

```python
txt_exports = F.TXTExports(
    fields=['solute'],
    labels=['mobile'],
    times=[100, 17000, 8e5],
    folder=folder
    )

model_barrier.dt = F.Stepsize(
    initial_value=5,
    stepsize_change_ratio=1.1,
    milestones=txt_exports.times
)

```

The produced `mobile.txt` file is then corect:

```auto
x,t=100.0s,t=17000.0s,t=800000.0s
2.040816326530612004e-08,1.801426784891369688e+14,1.809394334257680312e+14,1.822464499449328125e+14
0.000000000000000000e+00,1.838152232121175000e+14,1.838152232121175312e+14,1.838152232121175312e+14
4.081632653061224008e-08,1.764701337983499688e+14,1.780636436413083438e+14,1.806776766777480625e+14
2.040816326530612004e-08,1.801426784891368750e+14,1.809394334257678750e+14,1.822464499449327188e+14

```

---

<div class="post-metadata">

**Author:** ![remidm](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/remidm/32/4_2.png) [@remidm](https://festim.discourse.group/u/remidm)\
**Post date:** [December 22, 2023, 8:28pm UTC](https://festim.discourse.group/t/file-formatting-bug-in-the-task4-workshop-file/25/3 "2023-12-22T20:28:23Z")

</div>

@VVKulagin maybe we could do something about this: at the initialisation phase, we could check if the times of the `TXTExport` are in the `Settings.milestones`, and if not, add them (with a message to the user).

---

<div class="post-metadata">

**Author:** ![ee-nn](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/ee-nn/32/6_2.png) [@ee-nn](https://festim.discourse.group/u/ee-nn)\
**Post date:** [December 22, 2023, 8:39pm UTC](https://festim.discourse.group/t/file-formatting-bug-in-the-task4-workshop-file/25/4 "2023-12-22T20:39:55Z")

</div>

I see. Thanks for the clarification and pointers! Great to know there’s a simple fix 🙂
