Debugging Failed Binaries
During evolution in the BinaryPopulation
, all Exceptions
are caught
to allow the population to keep evolving in the event a single binary
enocunters an error. Here we go over some methods to help debug errors.
We cause an error by using a broken evolutionary step:
1from posydon.popsyn.binarypopulation import BinaryPopulation
2from posydon.binary_evol.simulationproperties import SimulationProperties
3from posydon.binary_evol.flow_chart import flow_chart
4from posydon.binary_evol.CE.step_CEE import StepCEE
5from posydon.binary_evol.SN.step_SN import StepSN
6from posydon.binary_evol.step_end import step_end
7from posydon.binary_evol.MESA.step_mesa import CO_HeMS_step, MS_MS_step, CO_HMS_RLO_step
8from posydon.binary_evol.DT.step_detached import detached_step
9from posydon.binary_evol.DT.double_CO import DoubleCO
10from posydon.binary_evol.simulationproperties import TimingHooks, StepNamesHooks
11
12class my_new_StepSN(StepSN):
13 def __call__(self, binary):
14 # use the StepSN call
15 super().__call__(binary)
16 # break here
17 raise ValueError(f'{str(binary)} failed in my new step')
18
19mesa_step_kwargs = dict(
20 interpolation_method='linear3c_kNN',
21 save_initial_conditions=False,
22 track_interpolation=False
23)
24
25sim_kwargs = dict(
26 flow = (flow_chart, {}),
27 step_HMS_HMS = (MS_MS_step, mesa_step_kwargs),
28 step_CO_HeMS = (CO_HeMS_step, mesa_step_kwargs),
29 step_CO_HMS_RLO = (CO_HMS_RLO_step, mesa_step_kwargs),
30 step_detached = (detached_step, {}),
31 step_CE = (StepCEE, dict(core_definition_H_fraction= 0.1,)),
32 step_SN = (my_new_StepSN, {}),
33 step_dco = (DoubleCO, {}),
34 step_end = (step_end, {}),
35 extra_hooks = [(TimingHooks, {}),(StepNamesHooks, {})]
36)
37
38kwargs = {'number_of_binaries' : 15,
39 'primary_mass_min' : 7,
40 'primary_mass_max' : 127,
41 'secondary_mass_scheme' : 'flat_mass_ratio',
42 'secondary_mass_min': 1,
43 'secondary_mass_max': 127,
44 'orbital_separation_min': 1,
45 'orbital_separation_max': 3e3,
46 'eccentricity_scheme':'zero',
47 'extra_columns' : ['step_times','step_names'],
48 'only_select_columns' : ['state', 'event', 'time', 'lg_mtransfer_rate',
49 'orbital_period'],
50 'include_S1' : True ,
51 'S1_kwargs' : {'only_select_columns' : ['state', 'mass',
52 'log_R', 'center_h1','center_he4',
53 'he_core_mass', 'surface_he4', 'surface_h1',
54 'lg_mdot'],
55 'scalar_names' : ['natal_kick_array', 'SN_type']},
56 'include_S2' : True,
57 'S2_kwargs' : {'only_select_columns' : ['state', 'mass',
58 'log_R', 'center_h1','center_he4',
59 'he_core_mass', 'surface_he4', 'surface_h1',
60 'lg_mdot'],
61 'scalar_names' : ['natal_kick_array', 'SN_type']},
62 'star_formation' : 'burst',
63 'max_simulation_time' : 13.7e9,
64 }
65
66pop = BinaryPopulation(
67 population_properties=sim_prop,
68 entropy = 12345678,
69 **kwargs
70)
71
72pop.evolve(breakdown_to_df=False, from_hdf=False, tqdm=True, **kwargs)
After running the script above we can use the BinaryPopulation.find_failed
instance method which returns a list of the failed binaries in the population.
failed_binaries = pop.find_failed()
if failed_binaries:
print( failed_binaries[0].traceback )
The BinaryStar
instances that fail during evolution will have a
traceback
attribute showing the string representation (not the actual
stack
traceback):
Traceback (most recent call last):
File "/Users/kylerocha/Private/Github/POSYDON/posydon/popsyn/binarypopulation.py", line 153, in _safe_evolve
binary.evolve()
File "/Users/kylerocha/Private/Github/POSYDON/posydon/binary_evol/binarystar.py", line 183, in evolve
self.run_step()
File "/Users/kylerocha/Private/Github/POSYDON/posydon/binary_evol/binarystar.py", line 214, in run_step
next_step(self)
File "<ipython-input-1-3023b4d9482c>", line 32, in __call__
raise ValueError(f'{str(binary)} failed in my new step')
ValueError: BinaryStar(detached, None, p=6820.50, S1=(BH,M=26.79), S2=(H-rich_Shell_H_burning,M=35.61)) failed in my new step
If we want to go further we could also take the binary out of the population
and evolve it. If using a jupyter notebook
, you can enter the python
debugger by raising the error again and using the magic command %debug
in another cell.
failing_binary = failed_binaries[0]
failing_binary.restore()
failing_binary.evolve()
%debug
See the debugger commands for help.