Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIME-X Test Hackathon @ TUD: Test for SwitchEstimator #404

Merged
merged 36 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
92cf385
Added piecewise linear interpolation to SwitchEstimator
lisawim Oct 25, 2023
4040463
Started with test for SwitchEstimator [WIP]
lisawim Oct 25, 2023
7d6e6f8
Merge remote-tracking branch 'upstream/master' into test_hackathon
lisawim Oct 26, 2023
2a79717
Test to proof sum_restarts when event occuring at boundary
lisawim Oct 26, 2023
4d98155
Started with test to check adapt_interpolation_info [WIP]
lisawim Oct 27, 2023
42aaaf5
Added test for SE.adapt_interpolation_info()
lisawim Oct 27, 2023
0720942
Merge remote-tracking branch 'upstream/master' into test_hackathon
lisawim Nov 29, 2023
7997720
Merge remote-tracking branch 'upstream/master' into test_hackathon
lisawim Feb 22, 2024
2cad220
Update linear interpolation + logging + changing tolerances
lisawim Feb 22, 2024
d3c3217
Test for linear interpolation + update of other test
lisawim Feb 22, 2024
19ab5ba
Correction for finite difference + adaption tolerance
lisawim Feb 22, 2024
2268cfa
Added test for DAE case for SE
lisawim Feb 23, 2024
9a6350c
Choice of FD seems to be important for performance of SE
lisawim Feb 24, 2024
e1295a3
Removed attributes from dummy probs (since the parent classes have it)
lisawim Feb 24, 2024
fb0311e
Merge remote-tracking branch 'upstream/master' into test_hackathon
lisawim Feb 24, 2024
421428e
Test for dummy problems + using functions from battery_model.py
lisawim Feb 25, 2024
f4a5294
Moved standard params for test to function
lisawim Feb 25, 2024
019e78b
Updated hardcoded solutions for battery models
lisawim Feb 25, 2024
4bd86c4
Updated hardcoded solutions for DiscontinuousTestODE
lisawim Feb 25, 2024
487573a
Updated docu in SE for FDs
lisawim Feb 25, 2024
28425da
Lagrange Interpolation works better with baclward FD and alpha=0.9
lisawim Feb 26, 2024
b5fadcc
Added test for state function + global error
lisawim Feb 27, 2024
658d905
Merge remote-tracking branch 'upstream/master' into test_hackathon
lisawim Feb 27, 2024
563bcfd
Updated LogEvent hooks
lisawim Mar 5, 2024
22f2bcc
Updated hardcoded solutions again
lisawim Mar 5, 2024
b07b0cc
Merge remote-tracking branch 'upstream/master' into test_hackathon
lisawim Mar 5, 2024
8ccbebf
Adapted test_problems.py
lisawim Mar 5, 2024
0bfcae7
Minor changes
lisawim Mar 5, 2024
827a8ed
Updated tests
lisawim Mar 7, 2024
c3107c5
Speed-up test for buck converter
lisawim Mar 7, 2024
74ee1ff
Black..
lisawim Mar 7, 2024
872e81e
Use msg about convergence info in Newton in SE
lisawim Mar 7, 2024
bc751fd
Moved dummy problem to file
lisawim Apr 11, 2024
e00236c
Merge remote-tracking branch 'upstream/master' into test_hackathon
lisawim Apr 11, 2024
e8bf17e
Speed up loop using mask
lisawim Apr 18, 2024
2affa75
Removed loop
lisawim Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def get_switching_info(self, u, t):
m_guess = m - 1
break

state_function = [u[m][0] - 5 for m in range(len(u))] if switch_detected else []
state_function = [u[m][0] - 5 for m in range(len(u))]
return switch_detected, m_guess, state_function

def count_switches(self):
Expand Down
21 changes: 12 additions & 9 deletions pySDC/projects/PinTSimE/battery_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,13 @@ def generateDescription(
'convergence_controllers': convergence_controllers,
}

return description, controller_params
# instantiate controller
controller = controller_nonMPI(num_procs=1, controller_params=controller_params, description=description)

return description, controller_params, controller


def controllerRun(description, controller_params, t0, Tend, exact_event_time_avail=False):
def controllerRun(description, controller_params, controller, t0, Tend, exact_event_time_avail=False):
"""
Executes a controller run for a problem defined in the description.

Expand All @@ -180,6 +183,8 @@ def controllerRun(description, controller_params, t0, Tend, exact_event_time_ava
Contains all information for a controller run.
controller_params : dict
Parameters needed for a controller run.
controller : pySDC.core.Controller
Controller to do the stuff.
t0 : float
Starting time of simulation.
Tend : float
Expand All @@ -193,9 +198,6 @@ def controllerRun(description, controller_params, t0, Tend, exact_event_time_ava
Raw statistics from a controller run.
"""

# instantiate controller
controller = controller_nonMPI(num_procs=1, controller_params=controller_params, description=description)

# get initial values on finest level
P = controller.MS[0].levels[0].prob
uinit = P.u_exact(t0)
Expand Down Expand Up @@ -233,7 +235,7 @@ def main():
'max_restarts': 50,
'recomputed': False,
'tol_event': 1e-10,
'alpha': 1.0,
'alpha': 0.96,
'exact_event_time_avail': None,
}

Expand All @@ -244,8 +246,8 @@ def main():

hook_class = [LogSolution, LogEventBattery, LogEmbeddedErrorEstimate, LogStepSize]

use_detection = [True]
use_adaptivity = [True]
use_detection = [True, False]
use_adaptivity = [True, False]

for problem, sweeper in zip([battery, battery_implicit], [imex_1st_order, generic_implicit]):
for defaults in [False, True]:
Expand Down Expand Up @@ -360,7 +362,7 @@ def runSimulation(problem, sweeper, all_params, use_adaptivity, use_detection, h

restol = -1 if use_A else handling_params['restol']

description, controller_params = generateDescription(
description, controller_params, controller = generateDescription(
dt=dt,
problem=problem,
sweeper=sweeper,
Expand All @@ -381,6 +383,7 @@ def runSimulation(problem, sweeper, all_params, use_adaptivity, use_detection, h
stats, t_switch_exact = controllerRun(
description=description,
controller_params=controller_params,
controller=controller,
t0=interval[0],
Tend=interval[-1],
exact_event_time_avail=handling_params['exact_event_time_avail'],
Expand Down
2 changes: 1 addition & 1 deletion pySDC/projects/PinTSimE/buck_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def main():
use_adaptivity=use_adaptivity,
use_detection=use_detection,
hook_class=hook_class,
interval=(0.0, 2e-2),
interval=(0.0, 1e-2),
dt_list=[1e-5, 2e-5],
nnodes=[M_fix],
)
Expand Down
3 changes: 2 additions & 1 deletion pySDC/projects/PinTSimE/discontinuous_test_ODE.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ def main():
'max_restarts': 50,
'recomputed': False,
'tol_event': 1e-12,
'alpha': 1.0,
'alpha': 0.96,
'exact_event_time_avail': True,
'typeFD': 'backward',
}

# ---- all parameters are stored in this dictionary ----
Expand Down
15 changes: 11 additions & 4 deletions pySDC/projects/PinTSimE/estimation_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def run_estimation_check():
'max_restarts': 50,
'recomputed': False,
'tol_event': 1e-10,
'alpha': 1.0,
'alpha': 0.96,
'exact_event_time_avail': None,
}

Expand Down Expand Up @@ -114,7 +114,7 @@ def run_estimation_check():

plotAccuracyCheck(u_num, prob_cls_name, M_fix)

plotStateFunctionAroundEvent(u_num, prob_cls_name, M_fix)
# plotStateFunctionAroundEvent(u_num, prob_cls_name, M_fix)

plotStateFunctionOverTime(u_num, prob_cls_name, M_fix)

Expand Down Expand Up @@ -187,6 +187,9 @@ def plotStateFunctionAroundEvent(u_num, prob_cls_name, M_fix): # pragma: no cov
Routine that plots the state function at time before the event, exactly at the event, and after the event. Note
that this routine does make sense only for a state function that remains constant after the event.

TODO: Function still does not work as expected. Every time when the switch estimator is adapted, the tolerances
does not suit anymore!

Parameters
----------
u_num : dict
Expand Down Expand Up @@ -239,15 +242,19 @@ def plotStateFunctionAroundEvent(u_num, prob_cls_name, M_fix): # pragma: no cov

if use_SE:
t_switches = [u_num[dt][M_fix][use_SE][use_A]['t_switches'] for dt in dt_list]
t_switch = [t_event[i] for t_event in t_switches]
for t_switch_item in t_switches:
for m in range(1, len(t_switch_item)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how many iterations does this typically have? If it's a lot, you may want to speed this up using masks with sth. like

mask = np.append([True], np.abs(t_swtich_item[1:] - t_switch_item[:-1] > 1e-10)
t_switch_item = t_switch_item[mask]

If the loop is entered only a couple of times, don't bother.

if np.isclose(t_switch_item[m - 1], t_switch_item[m], atol=1e-10):
t_switch_item.pop(m - 1)

t_switch = [t_event[i] for t_event in t_switches]
ax[0, ind].plot(
dt_list,
[
h_item[m]
for (t_item, h_item, t_switch_item) in zip(t, h, t_switch)
for m in range(len(t_item))
if abs(t_item[m] - t_switch_item) <= 1e-14
if abs(t_item[m] - t_switch_item) <= 2.7961188919789493e-11
brownbaerchen marked this conversation as resolved.
Show resolved Hide resolved
],
color='limegreen',
marker='s',
Expand Down
Loading
Loading