Error in Criticality Search After Depletion

I am running a depletion simulation, renaming and categorizing the output into folders, before running a criticality search with Boron. When it goes to the criticality search I get the following error,

This is the code,

time_steps = [5/24] * 8
current_time = 0.0

for i, dt in enumerate(time_steps, start=1):
    current_time += dt
    step_id = f"{current_time:.10f}_days" #Assigns the step id to the number of days

    # #Tallies collected before refuelling begins
    # tallies_reactionR_file = openmc.Tallies()
    
    # tally_RR = openmc.Tally(name = 'Reaction rates')
    # tally_RR.filters = [openmc.MaterialFilter(fuel_materials)]
    # tally_RR.scores = ['total']
    # tally_RR.nuclides = ['U235', 'U238', 'Pu239', 'Pu241']
    # tallies_reactionR_file.append(tally_RR)
    
    # tally_heating = openmc.Tally(name = 'Heating')
    # tally_heating.scores =['heating']
    # tallies_reactionR_file.append(tally_heating)
    # tallies_reactionR_file.export_to_xml()

    model = openmc.Model(
        geometry=geometry,
        materials=materials,
        settings=settings,
        # tallies=tallies_reactionR_file
    )
    operator = openmc.deplete.CoupledOperator(model, "chain.xml", normalization_mode="energy-deposition")
    integrator = openmc.deplete.PredictorIntegrator(operator, [time_steps[i-1]], power, timestep_units='d', solver='cram16').integrate()

    rename_and_move_openmc_outputs(step_id)
    filename = f"statepoint.20_{step_id}.h5"
    # construct the statepoint path to call in later statepoints
    statepoint_path = os.path.join(parent_folder_name, step_id, filename)

    results = openmc.deplete.Results(f'{parent_folder_name}/{step_id}/depletion_results_{step_id}.h5')
    materials = results.export_to_materials(1)
    
    #Arguments for the boron criticality function
    Boron_function_args = {
    
    #Misc
    'boron_enrichment': boron_enrichment,
        
    'fuel_only_array' : fuel_only_array,
    'fuel_materials' : [],
    
    #Adjuster Arrays
    'Adjuster_right_front_array' : Adjuster_right_front_array,
    'Adjuster_left_front_array' : Adjuster_left_front_array,
    'Adjuster_right_back_array' : Adjuster_right_back_array,
    'Adjuster_left_back_array' : Adjuster_left_back_array,
        
    'Adjuster_right_front_empty_array' : Adjuster_right_front_empty_array,
    'Adjuster_left_front_empty_array' : Adjuster_left_front_empty_array,
    'Adjuster_right_back_empty_array' : Adjuster_right_back_empty_array,
    'Adjuster_left_back_empty_array' : Adjuster_left_back_empty_array,
    
    #Corner adjuster Arrays
    'Adjuster_right_front_corner_array' : Adjuster_right_front_corner_array,
    'Adjuster_left_front_corner_array' : Adjuster_left_front_corner_array,
    'Adjuster_right_back_corner_array' : Adjuster_right_back_corner_array,
    'Adjuster_left_back_corner_array' : Adjuster_left_back_corner_array,
    
    'Adjuster_right_front_corner_empty_array' : Adjuster_right_front_corner_empty_array,
    'Adjuster_left_front_corner_empty_array' : Adjuster_left_front_corner_empty_array,
    'Adjuster_right_back_corner_empty_array' : Adjuster_right_back_corner_empty_array,
    'Adjuster_left_back_corner_empty_array' : Adjuster_left_back_corner_empty_array,
    
    #LZC arrays
    'LZC_right_front_corner_array' : LZC_right_front_corner_array,
    'LZC_left_front_corner_array' : LZC_left_front_corner_array,
    'LZC_right_back_corner_array' : LZC_right_back_corner_array,
    'LZC_left_back_corner_array' : LZC_left_back_corner_array,
    
    #Empty LZC arrays
    'LZC_right_front_corner_empty_array' : LZC_right_front_corner_empty_array,
    'LZC_left_front_corner_empty_array' : LZC_left_front_corner_empty_array,
    'LZC_right_back_corner_empty_array' : LZC_right_back_corner_empty_array,
    'LZC_left_back_corner_empty_array' : LZC_left_back_corner_empty_array,
    
    'All_but_fuel_array' : All_but_fuel_array,
    'fuel_array' : fuel_array
    }

            #Parametized model for boron criticality search
    def Boron_build_model(ppm_Boron, materials, **kwargs):
        openmc.reset_auto_ids()  # clears ID counters and registries
        
        #Misc
        boron_enrichment = kwargs["boron_enrichment"]
    
        #arrays used for fuel
        fuel_only_array = kwargs["fuel_only_array"]
        fuel_materials = []
        
        #Adjuster Arrays
        Adjuster_right_front_array = kwargs["Adjuster_right_front_array"]
        Adjuster_left_front_array = kwargs["Adjuster_left_front_array"]
        Adjuster_right_back_array = kwargs["Adjuster_right_back_array"]
        Adjuster_left_back_array = kwargs["Adjuster_left_back_array"]
        
        Adjuster_right_front_empty_array = kwargs["Adjuster_right_front_empty_array"]
        Adjuster_left_front_empty_array = kwargs["Adjuster_left_front_empty_array"]
        Adjuster_right_back_empty_array = kwargs["Adjuster_right_back_empty_array"]
        Adjuster_left_back_empty_array = kwargs["Adjuster_left_back_empty_array"]
        
        #Corner adjuster Arrays
        Adjuster_right_front_corner_array = kwargs["Adjuster_right_front_corner_array"]
        Adjuster_left_front_corner_array = kwargs["Adjuster_left_front_corner_array"]
        Adjuster_right_back_corner_array = kwargs["Adjuster_right_back_corner_array"]
        Adjuster_left_back_corner_array = kwargs["Adjuster_left_back_corner_array"]
        
        Adjuster_right_front_corner_empty_array = kwargs["Adjuster_right_front_corner_empty_array"]
        Adjuster_left_front_corner_empty_array = kwargs["Adjuster_left_front_corner_empty_array"]
        Adjuster_right_back_corner_empty_array = kwargs["Adjuster_right_back_corner_empty_array"]
        Adjuster_left_back_corner_empty_array = kwargs["Adjuster_left_back_corner_empty_array"]
        
        #LZC arrays
        LZC_right_front_corner_array = kwargs["LZC_right_front_corner_array"]
        LZC_left_front_corner_array = kwargs["LZC_left_front_corner_array"]
        LZC_right_back_corner_array = kwargs["LZC_right_back_corner_array"]
        LZC_left_back_corner_array = kwargs["LZC_left_back_corner_array"]
        
        #Empty LZC arrays
        LZC_right_front_corner_empty_array = kwargs["LZC_right_front_corner_empty_array"]
        LZC_left_front_corner_empty_array = kwargs["LZC_left_front_corner_empty_array"]
        LZC_right_back_corner_empty_array = kwargs["LZC_right_back_corner_empty_array"]
        LZC_left_back_corner_empty_array = kwargs["LZC_left_back_corner_empty_array"]
        
        
        All_but_fuel_array = kwargs["All_but_fuel_array"]
        fuel_array = kwargs["fuel_array"]
        #Variable deinitions
        #Dimensions in cm
        r_fuel = 0.61215
        r_clad = 0.65405
        
        pitch = 28.575
        
        pressure_tube_ir = 5.16890
        pressure_tube_or = 5.60320
        calandria_ir = 6.45
        calandria_or = 6.58750
        
        fuel_bundle_length = 49.33
        sheath_length = 49.53
        
        r_coolant = 2.5
        
        Calandria_vessel_ir = 337.8
        Calandria_vessel_or = 379.7
        Calandria_vessel_length = 594.36
        
        reflective_distance_x = 171.45
        reflective_distance_y = -171.45
        
        LZC_ir = 9.3/2
        LZC_or = 9.5/2
        Adjuster_ir = 7.42/2
        Adjuster_or = 7.62/2
        Adjuster_offset_front = 5.705
        Adjuster_offset_back = -5.705
        
        #Void Dimensions
        Void_bot = 400.0
        Void_top = 400.0
        Void_front = 300.0
        Void_back = 300.0
        Void_right = 400.0
        Void_left = 400.0
        Void_radius = 380.0
        
        #Mesh Dimensions
        mesh_lower_x = 210.0
        mesh_lower_y = 172.0
        mesh_lower_z = 300.0
        mesh_upper_x = 172.0
        mesh_upper_y = 210.0
        mesh_upper_z = 300.0
        
        #Temperatures in Kelvin
        moderator_temp = 323.15
        fuel_temp = 1200
        coolant_temp = 558.15
        clad_temp = 613.15
        pressure_tube_temp = 578.15
        anulus_temp = 398.85
        calandria_tube_temp = 333.15
        calandria_vessel_temp = 318.15
        adjuster_temp = 323.15
        LCZ_temp = 323.15
        
        #Densities in g/cm3
        moderator_dens = 1.096
        fuel_dens = 10.6
        coolant_dens = 0.7411
        clad_dens = 6.56
        pressure_tube_dens = 6.56
        anulus_dens = 1.6834
        calandria_tube_dens = 6.56
        calandria_vessel_dens = 7.9
        adjuster_dens = 7.9
        LCZ_dens = 0.941700
        
        #D2O Atomic Concentraion in homogenized adjuster rods between 0.91 (this results in the 15mk) and 1
        D2OC = 0.91
        
        
        #Settings
        batches = 20
        #Need at least 100 entries removed, so 10 batches*10 gens, or 100 batches*1 gen
        inactive_batches = 5
        generations = 20
        particles = 100
        particles_boron = 1000
        particles_adjuster = 1000
        particles_si = 1000
        
        # Remove old moderator completely
        materials = openmc.Materials([m for m in materials if m.name != "Moderator"])

        # Reconstruct a new moderator material
        moderator = openmc.Material(4, "Moderator")
        moderator.add_nuclide('H2', 1.995)
        moderator.add_nuclide('H1', 0.005)
        moderator.add_nuclide('O16', 1.0)
        moderator.add_element('B', ppm_Boron, enrichment=boron_enrichment, enrichment_target='B10', percent_type='ao')
        moderator.set_density('g/cm3', moderator_dens)
        moderator.add_s_alpha_beta('c_D_in_D2O')
        # Append to materials and re-export
        materials.append(moderator)
        materials.cross_sections = '/home/smrcenter/openmc/endfb80/cross_sections.xml'
        materials.export_to_xml()
...
...
...
geometry = openmc.Geometry()
    geometry.root_universe = root_universe
    geometry.export_to_xml()
    
    settings = openmc.Settings()
    bounds = [-172.0, -172.0, -300.0, 172.0, 172.0, 300.0]
    
    # School Settings
    uniform_dist= openmc.stats.Box(bounds[:3], bounds[3:])
    settings.source = openmc.IndependentSource(
        space=uniform_dist, 
    )
    
    settings.batches = batches
    settings.inactive = inactive_batches
    settings.particles = particles_boron
    settings.generations_per_batch = generations
    settings.temperature['method'] = 'interpolation'
    settings.temperature['tolerance'] = 400
    settings.temperature['range'] = [0.0, 2400.0]
    settings.output = {'tallies': False}
    settings.export_to_xml()
    
    model = openmc.Model(geometry, materials, settings)
    return model

# initial_ppm = 1.97e-5
# guess = 1.97e-5
# guess = initial_ppm if i == 0 else ppm_Boron
# crit_ppm, guesses, keffs = openmc.search_for_keff(lambda ppm,**kwargs: Boron_build_model(ppm, materials, **kwargs), initial_guess=guess, model_args=Boron_function_args,
#                                               tol=1e-6, print_iterations=True, run_args={'output': False})
crit_ppm, guesses, keffs = openmc.search_for_keff(lambda ppm,**kwargs: Boron_build_model(ppm, materials, **kwargs), bracket=[0, 1.0e-4], model_args=Boron_function_args,
                                              tol=5e-2, print_iterations=True, run_args={'output': True})
print('Critical Boron Concentration: {:.6e}'.format(crit_ppm))
ppm_Boron = crit_ppm
openmc.reset_auto_ids()  # clears ID counters and registries
if os.path.exists("model.xml"):
    os.remove("model.xml")

materials = openmc.Materials([m for m in materials if m.name != "Moderator"])
Moderator = openmc.Material(4, "Moderator")
# add nuclides and boron using crit_ppm here
Moderator.add_nuclide('H2', 1.995)
Moderator.add_nuclide('H1', 0.005)
Moderator.add_nuclide('O16', 1.0)
Moderator.add_element('B', ppm_Boron, enrichment=boron_enrichment,
                    enrichment_target='B10', percent_type='ao')
Moderator.set_density('g/cm3', moderator_dens)
Moderator.add_s_alpha_beta('c_D_in_D2O')
materials.append(Moderator)
materials.export_to_xml()

I removed the geometry construction as it is very long and shouldn’t be an issue here since the geometry works on its own just fine. The error I am getting occurs as soon as it tries to call the material section. I have had this exact script work with a simplified model, I have completed depletion on this complicated model before, and I have run an independent criticality search without the depletion aspect, it just appears that my script somehow results in the data getting scrambled or something when putting it all together. I was wondering if anyone had any Idea how I might be able to better troubleshoot this issue (logs and whatnot), or if they had a fix, or if they have another method where I could preform the desired functions I am looking for (depletion into criticality search back into depletion). The reasoning for some of my script can be seen in the following posts I made,

@paulromano I’m sorry to @ you, but I think you might be one of the only people knowledgeable enough and willing enough to help. Is there a better way to run depletion into criticality search and back into depletion (and later depletion into refueling, into criticality search, repeating for the entire fuel lifecycle), or if not is it soon to be developed? This would be very useful for simulating the depletion of a reactor’s fuel as I don’t know many that don’t have some kind of criticality balancing occurring over their lifespan, and in my case which is a CANDU reactor, refueling and criticality balancing is required.