|
20 | 20 | DIRKStrategy, |
21 | 21 | ERKStrategy, |
22 | 22 | AdaptivityPolynomialError, |
| 23 | + cmap, |
23 | 24 | ) |
24 | 25 | from pySDC.helpers.plot_helper import setup_mpl, figsize_by_journal |
25 | 26 | from pySDC.helpers.stats_helper import get_sorted |
@@ -392,6 +393,102 @@ def plot_fault_vdp(bit=0): # pragma: no cover |
392 | 393 | savefig(fig, f'fault_bit_{bit}') |
393 | 394 |
|
394 | 395 |
|
| 396 | +def plot_fault_Lorenz(bit=0): # pragma: no cover |
| 397 | + """ |
| 398 | + Make a plot showing the impact of a fault on the Lorenz attractor without any resilience. |
| 399 | + The faults are inserted in the last iteration in the last node in x such that you can best see the impact. |
| 400 | +
|
| 401 | + Args: |
| 402 | + bit (int): The bit that you want to flip |
| 403 | +
|
| 404 | + Returns: |
| 405 | + None |
| 406 | + """ |
| 407 | + from pySDC.projects.Resilience.fault_stats import ( |
| 408 | + FaultStats, |
| 409 | + BaseStrategy, |
| 410 | + ) |
| 411 | + from pySDC.projects.Resilience.hook import LogData |
| 412 | + |
| 413 | + stats_analyser = FaultStats( |
| 414 | + prob=run_Lorenz, |
| 415 | + strategies=[BaseStrategy()], |
| 416 | + faults=[False, True], |
| 417 | + reload=True, |
| 418 | + recovery_thresh=1.1, |
| 419 | + num_procs=1, |
| 420 | + mode='combination', |
| 421 | + ) |
| 422 | + |
| 423 | + strategy = BaseStrategy() |
| 424 | + |
| 425 | + my_setup_mpl() |
| 426 | + fig, ax = plt.subplots(figsize=figsize_by_journal(JOURNAL, 0.8, 0.5)) |
| 427 | + colors = ['grey', strategy.color, 'magenta'] |
| 428 | + ls = ['--', '-'] |
| 429 | + markers = [None, strategy.marker] |
| 430 | + do_faults = [False, True] |
| 431 | + superscripts = ['*', ''] |
| 432 | + labels = ['x', 'x'] |
| 433 | + |
| 434 | + run = 19 + 20 * bit |
| 435 | + |
| 436 | + for i in range(len(do_faults)): |
| 437 | + stats, controller, Tend = stats_analyser.single_run( |
| 438 | + strategy=BaseStrategy(), |
| 439 | + run=run, |
| 440 | + faults=do_faults[i], |
| 441 | + hook_class=[LogData], |
| 442 | + ) |
| 443 | + u = get_sorted(stats, type='u') |
| 444 | + faults = get_sorted(stats, type='bitflip') |
| 445 | + ax.plot( |
| 446 | + [me[0] for me in u], |
| 447 | + [me[1][0] for me in u], |
| 448 | + ls=ls[i], |
| 449 | + color=colors[i], |
| 450 | + label=rf'${{{labels[i]}}}^{{{superscripts[i]}}}$', |
| 451 | + marker=markers[i], |
| 452 | + markevery=500, |
| 453 | + ) |
| 454 | + for idx in range(len(faults)): |
| 455 | + ax.axvline(faults[idx][0], color='black', label='Fault', ls=':') |
| 456 | + print( |
| 457 | + f'Fault at t={faults[idx][0]:.2e}, iter={faults[idx][1][1]}, node={faults[idx][1][2]}, space={faults[idx][1][3]}, bit={faults[idx][1][4]}' |
| 458 | + ) |
| 459 | + ax.set_title(f'Fault in bit {faults[idx][1][4]}') |
| 460 | + |
| 461 | + ax.legend(frameon=True, loc='lower left') |
| 462 | + ax.set_xlabel(r'$t$') |
| 463 | + savefig(fig, f'fault_bit_{bit}') |
| 464 | + |
| 465 | + |
| 466 | +def plot_Lorenz_solution(): # pragma: no cover |
| 467 | + my_setup_mpl() |
| 468 | + |
| 469 | + fig, axs = plt.subplots(1, 2, figsize=figsize_by_journal(JOURNAL, 1, 0.4), sharex=True) |
| 470 | + |
| 471 | + strategy = BaseStrategy() |
| 472 | + desc = strategy.get_custom_description(run_Lorenz, num_procs=1) |
| 473 | + stats, controller, _ = run_Lorenz(custom_description=desc, Tend=strategy.get_Tend(run_Lorenz)) |
| 474 | + |
| 475 | + u = get_sorted(stats, recomputed=False, type='u') |
| 476 | + |
| 477 | + axs[0].plot([me[1][0] for me in u], [me[1][2] for me in u]) |
| 478 | + axs[0].set_ylabel('$z$') |
| 479 | + axs[0].set_xlabel('$x$') |
| 480 | + |
| 481 | + axs[1].plot([me[1][0] for me in u], [me[1][1] for me in u]) |
| 482 | + axs[1].set_ylabel('$y$') |
| 483 | + axs[1].set_xlabel('$x$') |
| 484 | + |
| 485 | + for ax in axs: |
| 486 | + ax.set_box_aspect(1.0) |
| 487 | + |
| 488 | + path = 'data/paper/Lorenz_sol.pdf' |
| 489 | + fig.savefig(path, bbox_inches='tight', transparent=True, dpi=200) |
| 490 | + |
| 491 | + |
395 | 492 | def plot_quench_solution(): # pragma: no cover |
396 | 493 | """ |
397 | 494 | Plot the solution of Quench problem over time |
@@ -586,6 +683,12 @@ def work_precision(): # pragma: no cover |
586 | 683 | all_problems(**{**all_params, 'work_key': 'param'}, mode='compare_strategies') |
587 | 684 |
|
588 | 685 |
|
| 686 | +def plot_recovery_rate_per_acceptance_threshold(problem): # pragma no cover |
| 687 | + stats_analyser = get_stats(problem) |
| 688 | + |
| 689 | + stats_analyser.plot_recovery_thresholds(thresh_range=np.linspace(0.5, 1.5, 1000), recoverable_only=True) |
| 690 | + |
| 691 | + |
589 | 692 | def make_plots_for_TIME_X_website(): # pragma: no cover |
590 | 693 | global JOURNAL, BASE_PATH |
591 | 694 | JOURNAL = 'JSC_beamer' |
@@ -636,11 +739,14 @@ def make_plots_for_adaptivity_paper(): # pragma: no cover |
636 | 739 |
|
637 | 740 |
|
638 | 741 | def make_plots_for_resilience_paper(): # pragma: no cover |
639 | | - compare_recovery_rate_problems(target='resilience', num_procs=1, strategy_type='SDC') |
| 742 | + plot_Lorenz_solution() |
| 743 | + plot_fault_Lorenz(0) |
| 744 | + plot_fault_Lorenz(20) |
640 | 745 | plot_RBC_solution() |
641 | | - plot_recovery_rate(get_stats(run_vdp)) |
642 | | - plot_fault_vdp(0) |
643 | | - plot_fault_vdp(13) |
| 746 | + compare_recovery_rate_problems(target='resilience', num_procs=1, strategy_type='SDC') |
| 747 | + # plot_recovery_rate(get_stats(run_Lorenz)) |
| 748 | + # plot_recovery_rate_per_acceptance_threshold(run_Lorenz) |
| 749 | + plt.show() |
644 | 750 |
|
645 | 751 |
|
646 | 752 | def make_plots_for_notes(): # pragma: no cover |
|
0 commit comments