@@ -105,6 +105,7 @@ def run_simulation(
105105 log_timestep_info : bool = False ,
106106 progress_bar : bool = True ,
107107 max_steps : int | None = None ,
108+ _use_jitted_run_loop : bool = False , # pylint: disable=invalid-name
108109) -> tuple [xr .DataTree , output .StateHistory ]:
109110 """Runs a TORAX simulation using the config and returns the outputs.
110111
@@ -114,6 +115,8 @@ def run_simulation(
114115 progress_bar: Whether to show a progress bar.
115116 max_steps: The maximum number of steps to take, if not provided, then the
116117 simulation will run until the maximum time is reached.
118+ _use_jitted_run_loop: If True, then a jitted run loop will be used. A
119+ temporary private argument used for testing.
117120
118121 Returns:
119122 A tuple of the simulation outputs in the form of a DataTree and the state
@@ -128,14 +131,27 @@ def run_simulation(
128131 step_fn ,
129132 ) = prepare_simulation (torax_config )
130133
131- state_history , post_processed_outputs_history , sim_error = run_loop .run_loop (
132- initial_state = initial_state ,
133- initial_post_processed_outputs = post_processed_outputs ,
134- step_fn = step_fn ,
135- log_timestep_info = log_timestep_info ,
136- progress_bar = progress_bar ,
137- max_steps = max_steps ,
138- )
134+ if _use_jitted_run_loop :
135+
136+ state_history , post_processed_outputs_history , sim_error = (
137+ jit_run_loop .run_loop (
138+ step_fn ,
139+ max_steps = max_steps ,
140+ log_timestep_info = log_timestep_info ,
141+ progress_bar = progress_bar ,
142+ )
143+ )
144+ else :
145+ state_history , post_processed_outputs_history , sim_error = (
146+ run_loop .run_loop (
147+ initial_state = initial_state ,
148+ initial_post_processed_outputs = post_processed_outputs ,
149+ step_fn = step_fn ,
150+ log_timestep_info = log_timestep_info ,
151+ progress_bar = progress_bar ,
152+ max_steps = max_steps ,
153+ )
154+ )
139155
140156 state_history = output .StateHistory (
141157 state_history = state_history ,
@@ -148,45 +164,3 @@ def run_simulation(
148164 state_history .simulation_output_to_xr (),
149165 state_history ,
150166 )
151-
152-
153- def run_simulation_jitted (
154- torax_config : model_config .ToraxConfig ,
155- max_steps : int | None = None ,
156- ) -> tuple [xr .DataTree , output .StateHistory ]:
157- """Runs a TORAX simulation using the config and returns the outputs.
158-
159- NOTE: This function doesn't guarantee that the simulation will complete. If
160- the simulation does not complete successfully, then the state history will
161- contain the error state `SimError.DID_NOT_REACH_T_FINAL` and a truncated
162- simulation history.
163-
164- Args:
165- torax_config: The TORAX config to use for the simulation.
166- max_steps: The maximum number of steps to take, if not provided, then the
167- maximum number of steps will be determined by the numerics.t_final and
168- numerics.min_dt.
169-
170- Returns:
171- A tuple of the simulation outputs in the form of a DataTree and the state
172- history which is intended for helpful use with debugging as it contains
173- the `CoreProfiles`, `CoreTransport`, `CoreSources`, `Geometry`, and
174- `PostProcessedOutputs` dataclasses for each step of the simulation.
175- """
176- step_fn = make_step_fn (torax_config )
177- states_history , post_processed_outputs_history , sim_error = (
178- jit_run_loop .run_loop (
179- step_fn ,
180- max_steps = max_steps ,
181- )
182- )
183- state_history = output .StateHistory (
184- state_history = states_history ,
185- post_processed_outputs_history = post_processed_outputs_history ,
186- sim_error = sim_error ,
187- torax_config = torax_config ,
188- )
189- return (
190- state_history .simulation_output_to_xr (),
191- state_history ,
192- )
0 commit comments