# Depletion post processing error

**URL:** <https://openmc.discourse.group/t/depletion-post-processing-error/4226>\
**Category:** User Support\
**Created:** [May 2, 2024, 12:00pm UTC](https://openmc.discourse.group/t/depletion-post-processing-error/4226 "2024-05-02T12:00:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pfelectron](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pfelectron](https://openmc.discourse.group/u/pfelectron)\
**Post date:** [May 2, 2024, 12:00pm UTC](https://openmc.discourse.group/t/depletion-post-processing-error/4226/1 "2024-05-02T12:00:25Z")

</div>

Dear experts, I encounter this error when I add the post processing script to my depletion code. How can I solve this error?  
My Script

```auto
# Instantiate the Tally
tally = openmc.Tally(name='mesh tally')
tally.filters = [mesh_filter]
tally.scores = ['fission']

# Add tally to collection
tallies.append(tally)

model.tallies = tallies
chain_file = '/home/pfelectron/srpopenmc/test2/test/depletion/data/depletion/chain_casl_.xml'
op = openmc.deplete.CoupledOperator(model, chain_file)

# Perform simulation using the predictor algorithm
time_steps = [30] * 6
# Depletion Post-Processing
previous_results = openmc.deplete.Results('depletion_results.h5')
materials_dep = previous_results.export_to_materials(time_steps)
materials_dep.export_to_xml() # extracts and replaces original materials.xml file
power = 174 # W/cm, for 2D simulations only (use W for 3D)
integrator = openmc.deplete.PredictorIntegrator(op, time_steps, power, timestep_units='d')
integrator.integrate()

```

Error

```auto
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[11], line 212
    210 # Depletion Post-Processing
    211 previous_results = openmc.deplete.Results('depletion_results.h5')
--> 212 materials_dep = previous_results.export_to_materials(time_steps)
    213 materials_dep.export_to_xml() # extracts and replaces original materials.xml file
    214 power = 174 # W/cm, for 2D simulations only (use W for 3D)

File ~/.local/lib/python3.10/site-packages/openmc/deplete/results.py:560, in Results.export_to_materials(self, burnup_index, nuc_with_data, path)
    526 def export_to_materials(
    527 self,
    528 burnup_index: int,
    529 nuc_with_data: Optional[Iterable[str]] = None,
    530 path: PathLike = 'materials.xml'
    531 ) -> Materials:
    532 """Return openmc.Materials object based on results at a given step
    533 
    534 .. versionadded:: 0.12.1
   (...)
    558 and original isotopic compositions of non-depletable materials
    559 """
--> 560 result = self[burnup_index]
    562 # Only materials found in the original materials.xml file will be
    563 # updated. If for some reason you have modified OpenMC to produce
    564 # new materials as depletion takes place, this method will not
    565 # work as expected and leave out that material.
    566 mat_file = Materials.from_xml(path)

TypeError: list indices must be integers or slices, not list

```

---

<div class="post-metadata">

**Author:** ![JustAnotherNeutron](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@JustAnotherNeutron](https://openmc.discourse.group/u/JustAnotherNeutron)\
**Post date:** [May 3, 2024, 10:47am UTC](https://openmc.discourse.group/t/depletion-post-processing-error/4226/2 "2024-05-03T10:47:39Z")

</div>

```auto
materials_dep = previous_results.export_to_materials(time_steps)

```

This will return the materials at a given time step, so rather than give the whole list you have to specify the time step index. If you want it at each time step you can loop over the length of the time\_steps list?

---

<div class="post-metadata">

**Author:** ![pfelectron](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pfelectron](https://openmc.discourse.group/u/pfelectron)\
**Post date:** [May 3, 2024, 12:26pm UTC](https://openmc.discourse.group/t/depletion-post-processing-error/4226/3 "2024-05-03T12:26:13Z")

</div>

> [@JustAnotherNeutron](#):
>
> This will return the materials at a given time step, so rather than give the whole list you have to specify the time step index. If you want it at each time step you can loop over the length of the time\_steps list?

How should I specify the time steps? Can you show an example? What do you mean by step index?

---

<div class="post-metadata">

**Author:** ![JustAnotherNeutron](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@JustAnotherNeutron](https://openmc.discourse.group/u/JustAnotherNeutron)\
**Post date:** [May 3, 2024, 2:45pm UTC](https://openmc.discourse.group/t/depletion-post-processing-error/4226/4 "2024-05-03T14:45:54Z")

</div>

Time step is specified by its list index, so in your case:

```auto
time_step = [30] * 6 # [30,30,30,30,30,30] <-- List of length 6 

```

The equivalent burnup step indices are then 0,1,2,3,4,5 - these are python list indices, the error youre getting is because you are giving a list and not a single value EQUATING to a burnup step.

So, the direct fix to the error would be (using the last time step as an example):

```auto
materials_dep = previous_results.export_to_materials(burnup_index = 5)

```

If you do this does it run?

EDIT: -1 would also work for the last time step (I would actually recommend this instead)
