pyrc.core.solver.handler#
- class HomogeneousSystemHandler(system_matrix: SparseSymbolicEvaluator | spmatrix | sparray, rc_solution: RCSolution, settings: Settings, print_progress=True, print_points: list | ndarray = None, batch_end=None, time_dependent_function=None, _initialize_temperature_function=True, **kwargs)#
Bases:
objectSystem Handler that is called (“as function”) by
solve_ivp.- Parameters:
system_matrix (spmatrix | sparray | SparseSymbolicEvaluator) – The system matrix. If constant, the type must be a sparse scipy matrix. If time dependent symbols are contained, the system matrix must be given in a
SparseSymbolicEvaluatorobject.rc_solution
settings
print_progress
print_points
batch_end
time_dependent_function (Callable, optional) –
A function that calculates all time dependent variables within the time step and returns them in the correct order as iterable (e.g. list). It gets parameters like this:
time_dependent_function(time, temperature_vector)or
time_dependent_function(time, temperature_vector, input_vector).To not run into Errors just use
*args,**kwargsat the end in case more values are passed then needed._initialize_temperature_function (bool, optional) – If
False, thedtemperature_dt_functionattribute is not set using the method_init_temperature_equation()Used in subclasses to prevent an early call of attributes that are created in the subclasses later on.kwargs (dict, optional) – Not used: Just to not raise an error if too much information is passed.
- __call__(t, temperature)#
The function the solve_ivp is going to solve.
- Parameters:
t
temperature
Notes
The input vector that is saved during the iteration of the solver at the t_eval
- Returns:
The resulting vector of the temperature derivative.
- Return type:
np.ndarray
- __init__(system_matrix: SparseSymbolicEvaluator | spmatrix | sparray, rc_solution: RCSolution, settings: Settings, print_progress=True, print_points: list | ndarray = None, batch_end=None, time_dependent_function=None, _initialize_temperature_function=True, **kwargs)#
System Handler that is called (“as function”) by
solve_ivp.- Parameters:
system_matrix (spmatrix | sparray | SparseSymbolicEvaluator) – The system matrix. If constant, the type must be a sparse scipy matrix. If time dependent symbols are contained, the system matrix must be given in a
SparseSymbolicEvaluatorobject.rc_solution
settings
print_progress
print_points
batch_end
time_dependent_function (Callable, optional) –
A function that calculates all time dependent variables within the time step and returns them in the correct order as iterable (e.g. list). It gets parameters like this:
time_dependent_function(time, temperature_vector)or
time_dependent_function(time, temperature_vector, input_vector).To not run into Errors just use
*args,**kwargsat the end in case more values are passed then needed._initialize_temperature_function (bool, optional) – If
False, thedtemperature_dt_functionattribute is not set using the method_init_temperature_equation()Used in subclasses to prevent an early call of attributes that are created in the subclasses later on.kwargs (dict, optional) – Not used: Just to not raise an error if too much information is passed.
- static format_t(t)#
- print_out_progress(t)#
Prints a formatted time stamp.
- Parameters:
t (float | int) – The time to format/print.
- set_new_t_eval(new_t_eval)#
Change the current t_eval.
- Parameters:
new_t_eval (array_like) – The new t_eval.
- class InhomogeneousSystemHandler(system_matrix, input_matrix, input_vector, rc_solution, functions_list, kwargs_functions: dict, t_eval=None, time_dependent_function=None, use_parallelization=False, core_count=8, print_progress=True, print_points=3600, settings: ~pyrc.core.settings.Settings = <pyrc.core.settings.Settings object>, first_time: float | int = 0, **kwargs)#
Bases:
HomogeneousSystemHandlerSystem Handler that is called (“as function”) by
solve_ivp.- Parameters:
system_matrix (spmatrix | sparray | SparseSymbolicEvaluator) – The system matrix. If constant, the type must be a sparse scipy matrix. If time dependent symbols are contained, the system matrix must be given in a
SparseSymbolicEvaluatorobject.rc_solution
settings
print_progress
print_points
batch_end
time_dependent_function (Callable, optional) –
A function that calculates all time dependent variables within the time step and returns them in the correct order as iterable (e.g. list). It gets parameters like this:
time_dependent_function(time, temperature_vector)or
time_dependent_function(time, temperature_vector, input_vector).To not run into Errors just use
*args,**kwargsat the end in case more values are passed then needed._initialize_temperature_function (bool, optional) – If
False, thedtemperature_dt_functionattribute is not set using the method_init_temperature_equation()Used in subclasses to prevent an early call of attributes that are created in the subclasses later on.kwargs (dict, optional) – Not used: Just to not raise an error if too much information is passed.
- __call__(t, temperature: ndarray)#
The function the solve_ivp is going to solve.
- Parameters:
t
temperature
Notes
The input vector that is saved during the iteration of the solver at the t_eval
- Returns:
The resulting vector of the temperature derivative.
- Return type:
np.ndarray
- calculate_kwargs(tau, temp_vector, _input_vector, **kwargs)#
- set_new_t_eval(new_t_eval)#
Change the current t_eval.
- Parameters:
new_t_eval (array_like) – The new t_eval.
- class SolveIVPHandler(system_handler: HomogeneousSystemHandler | InhomogeneousSystemHandler, max_saved_steps=None, method=None, max_step=None, rtol=None, atol=None, save_interval=None, save_path=None, save_prefix='', minimize_ram_usage=None, solve_settings=None, **kwargs)#
Bases:
objectHandler of the solving process with solve_ivp.
- Parameters:
system_handler (HomogeneousSystemHandler | InhomogeneousSystemHandler) – The system handler that holds the function to solve in __call__().
max_saved_steps (int, optional) – The maximum number of used seconds during one solve_ivp call. It defines the batch size in seconds. Using this prevents long solving time because the matrices become very big.
method (str, optional) – The method to use to solve the system (see scipy.solve_ivp).
max_step
rtol
atol
save_interval
save_path
save_prefix (str, optional) – This is the beginning of the name of the pickle file that is saved during the solving.
minimize_ram_usage (bool, optional) – If True, the solution is deleted if saved to minimize the RAM usage during runtime.
kwargs
- __init__(system_handler: HomogeneousSystemHandler | InhomogeneousSystemHandler, max_saved_steps=None, method=None, max_step=None, rtol=None, atol=None, save_interval=None, save_path=None, save_prefix='', minimize_ram_usage=None, solve_settings=None, **kwargs)#
Handler of the solving process with solve_ivp.
- Parameters:
system_handler (HomogeneousSystemHandler | InhomogeneousSystemHandler) – The system handler that holds the function to solve in __call__().
max_saved_steps (int, optional) – The maximum number of used seconds during one solve_ivp call. It defines the batch size in seconds. Using this prevents long solving time because the matrices become very big.
method (str, optional) – The method to use to solve the system (see scipy.solve_ivp).
max_step
rtol
atol
save_interval
save_path
save_prefix (str, optional) – This is the beginning of the name of the pickle file that is saved during the solving.
minimize_ram_usage (bool, optional) – If True, the solution is deleted if saved to minimize the RAM usage during runtime.
kwargs
- add_to_solution(new_t: list, new_y: list)#
- get_batches(t_span)#
- set_initial_values(**kwargs)#
- solve(t_span, y0, t_eval=None, continued_simulation: bool = False, expected_solution_size_mb=5000)#
Runs the solve_ivp in batches.
- Parameters:
t_span (tuple[int | float, int| float] :) – The start and end of the simulation in seconds. Usually it starts at 0: (0, end_seconds) See also: scipy.integrate.solve_ivp()
y0 (np.ndarray | Iterable | float | int) – The initial state of the system. See also: scipy.integrate.solve_ivp()
t_eval (np.ndarray | Iterable | float | int, optional) – Times at which to store the computed solution, must be sorted and lie within
t_span. If None (default), use points selected by the solver. See also: scipy.integrate.solve_ivp()continued_simulation (bool, optional) – If True, the first value of the first batch is not kept, because the simulation is continued.
expected_solution_size_mb (int | float, optional) – The expected solution size in Megabytes. Is used for RAM-Management: if not enough free memory is available, the method waits for 10 seconds and tries again for a total of 360 times before raising an error. The solution size depends on the size of the RC network and number of saved time steps.