Skip to content

Generic Scenarios in Difficulty Mode¤

apebench.scenarios.difficulty.Linear ¤

Bases: BaseScenario

Source code in apebench/scenarios/difficulty/_linear.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Linear(BaseScenario):
    gammas: tuple[float, ...] = (0.0, -4.0, 0.0, 0.0, 0.0)
    coarse_proportion: float = 0.5

    def get_ref_stepper(self):
        return ex.stepper.generic.DifficultyLinearStepper(
            num_spatial_dims=self.num_spatial_dims,
            num_points=self.num_points,
            linear_difficulties=self.gammas,
        )

    def get_coarse_stepper(self) -> ex.BaseStepper:
        return ex.stepper.generic.DifficultyLinearStepper(
            num_spatial_dims=self.num_spatial_dims,
            num_points=self.num_points,
            linear_difficulties=tuple(f * self.coarse_proportion for f in self.gammas),
        )

    def get_scenario_name(self) -> str:
        active_indices = []
        for i, a in enumerate(self.gammas):
            if a != 0.0:
                active_indices.append(i)
        return f"{self.num_spatial_dims}d_diff_linear_{'_'.join(str(i) for i in active_indices)}"
gammas class-attribute instance-attribute ¤
gammas: tuple[float, ...] = (0.0, -4.0, 0.0, 0.0, 0.0)
coarse_proportion class-attribute instance-attribute ¤
coarse_proportion: float = 0.5
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/difficulty/_linear.py
24
25
26
27
28
29
def get_scenario_name(self) -> str:
    active_indices = []
    for i, a in enumerate(self.gammas):
        if a != 0.0:
            active_indices.append(i)
    return f"{self.num_spatial_dims}d_diff_linear_{'_'.join(str(i) for i in active_indices)}"

apebench.scenarios.difficulty.LinearSimple ¤

Bases: Linear

Source code in apebench/scenarios/difficulty/_linear.py
32
33
34
35
36
37
class LinearSimple(Linear):
    linear_gamma: float = -4.0
    linear_term_order: int = 1

    def __post_init__(self):
        self.gammas = (0.0,) * self.linear_term_order + (self.linear_gamma,)
linear_gamma class-attribute instance-attribute ¤
linear_gamma: float = -4.0
linear_term_order class-attribute instance-attribute ¤
linear_term_order: int = 1
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/difficulty/_linear.py
24
25
26
27
28
29
def get_scenario_name(self) -> str:
    active_indices = []
    for i, a in enumerate(self.gammas):
        if a != 0.0:
            active_indices.append(i)
    return f"{self.num_spatial_dims}d_diff_linear_{'_'.join(str(i) for i in active_indices)}"

apebench.scenarios.difficulty.FirstFour ¤

Bases: Linear

Source code in apebench/scenarios/difficulty/_linear.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
class FirstFour(Linear):
    advection_gamma: float = -4.0
    diffusion_gamma: float = 4.0
    dispersion_gamma: float = 4.0
    hyp_diffusion_gamma: float = -4.0

    def __post_init__(self):
        self.gammas = (
            0.0,
            self.advection_gamma,
            self.diffusion_gamma,
            self.dispersion_gamma,
            self.hyp_diffusion_gamma,
        )

    def get_scenario_name(self) -> str:
        return f"{self.num_spatial_dims}d_diff_four"
advection_gamma class-attribute instance-attribute ¤
advection_gamma: float = -4.0
diffusion_gamma class-attribute instance-attribute ¤
diffusion_gamma: float = 4.0
dispersion_gamma class-attribute instance-attribute ¤
dispersion_gamma: float = 4.0
hyp_diffusion_gamma class-attribute instance-attribute ¤
hyp_diffusion_gamma: float = -4.0
__post_init__ ¤
__post_init__()
Source code in apebench/scenarios/difficulty/_linear.py
 97
 98
 99
100
101
102
103
104
def __post_init__(self):
    self.gammas = (
        0.0,
        self.advection_gamma,
        self.diffusion_gamma,
        self.dispersion_gamma,
        self.hyp_diffusion_gamma,
    )
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/difficulty/_linear.py
106
107
def get_scenario_name(self) -> str:
    return f"{self.num_spatial_dims}d_diff_four"

apebench.scenarios.difficulty.Nonlinear ¤

Bases: BaseScenario

Uses the single channel convection mode to not have channels grow with spatial dimensions.

By default single-channel Burgers

Source code in apebench/scenarios/difficulty/_nonlinear.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Nonlinear(BaseScenario):
    """
    Uses the single channel convection mode to not have channels grow with
    spatial dimensions.

    By default single-channel Burgers
    """

    gammas: tuple[float, ...] = (0.0, 0.0, 1.5, 0.0, 0.0)
    deltas: tuple[float, float, float] = (0.0, -1.5, 0.0)

    num_substeps: int = 1

    coarse_proportion: float = 0.5

    order: int = 2
    dealiasing_fraction: float = 2 / 3
    num_circle_points: int = 16
    circle_radius: float = 1.0

    def __post_init__(self):
        pass

    def _build_stepper(self, gammas, deltas):
        substepped_gammas = tuple(g / self.num_substeps for g in gammas)
        substepped_deltas = tuple(d / self.num_substeps for d in deltas)

        substepped_stepper = ex.stepper.generic.DifficultyNonlinearStepper(
            num_spatial_dims=self.num_spatial_dims,
            num_points=self.num_points,
            linear_difficulties=substepped_gammas,
            nonlinear_difficulties=substepped_deltas,
            order=self.order,
            dealiasing_fraction=self.dealiasing_fraction,
            num_circle_points=self.num_circle_points,
            circle_radius=self.circle_radius,
        )

        if self.num_substeps == 1:
            stepper = substepped_stepper
        else:
            stepper = ex.RepeatedStepper(substepped_stepper, self.num_substeps)

        return stepper

    def get_ref_stepper(self):
        return self._build_stepper(self.gammas, self.deltas)

    def get_coarse_stepper(self):
        return self._build_stepper(
            tuple(f * self.coarse_proportion for f in self.gammas),
            tuple(f * self.coarse_proportion for f in self.deltas),
        )

    def get_scenario_name(self) -> str:
        return f"{self.num_spatial_dims}d_diff_nonlin"
gammas class-attribute instance-attribute ¤
gammas: tuple[float, ...] = (0.0, 0.0, 1.5, 0.0, 0.0)
deltas class-attribute instance-attribute ¤
deltas: tuple[float, float, float] = (0.0, -1.5, 0.0)
num_substeps class-attribute instance-attribute ¤
num_substeps: int = 1
coarse_proportion class-attribute instance-attribute ¤
coarse_proportion: float = 0.5
order class-attribute instance-attribute ¤
order: int = 2
dealiasing_fraction class-attribute instance-attribute ¤
dealiasing_fraction: float = 2 / 3
num_circle_points class-attribute instance-attribute ¤
num_circle_points: int = 16
circle_radius class-attribute instance-attribute ¤
circle_radius: float = 1.0
_build_stepper ¤
_build_stepper(gammas, deltas)
Source code in apebench/scenarios/difficulty/_nonlinear.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def _build_stepper(self, gammas, deltas):
    substepped_gammas = tuple(g / self.num_substeps for g in gammas)
    substepped_deltas = tuple(d / self.num_substeps for d in deltas)

    substepped_stepper = ex.stepper.generic.DifficultyNonlinearStepper(
        num_spatial_dims=self.num_spatial_dims,
        num_points=self.num_points,
        linear_difficulties=substepped_gammas,
        nonlinear_difficulties=substepped_deltas,
        order=self.order,
        dealiasing_fraction=self.dealiasing_fraction,
        num_circle_points=self.num_circle_points,
        circle_radius=self.circle_radius,
    )

    if self.num_substeps == 1:
        stepper = substepped_stepper
    else:
        stepper = ex.RepeatedStepper(substepped_stepper, self.num_substeps)

    return stepper
get_ref_stepper ¤
get_ref_stepper()
Source code in apebench/scenarios/difficulty/_nonlinear.py
55
56
def get_ref_stepper(self):
    return self._build_stepper(self.gammas, self.deltas)
get_coarse_stepper ¤
get_coarse_stepper()
Source code in apebench/scenarios/difficulty/_nonlinear.py
58
59
60
61
62
def get_coarse_stepper(self):
    return self._build_stepper(
        tuple(f * self.coarse_proportion for f in self.gammas),
        tuple(f * self.coarse_proportion for f in self.deltas),
    )
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/difficulty/_nonlinear.py
64
65
def get_scenario_name(self) -> str:
    return f"{self.num_spatial_dims}d_diff_nonlin"

apebench.scenarios.difficulty.Convection ¤

Bases: BaseScenario

Source code in apebench/scenarios/difficulty/_convection.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Convection(BaseScenario):
    gammas: tuple[float, ...] = (0.0, 0.0, 1.5, 0.0, 0.0)
    convection_delta: float = -1.5
    conservative: bool = True

    num_substeps: int = 1

    coarse_proportion: float = 0.5

    order: int = 2
    dealiasing_fraction: float = 2 / 3
    num_circle_points: float = 16
    circle_radius: float = 1.0

    def __post_init__(self):
        self.num_channels = self.num_spatial_dims  # Overwrite

    def _build_stepper(self, gammas, delta):
        substepped_gammas = tuple(g / self.num_substeps for g in gammas)
        substepped_delta = delta / self.num_substeps

        substepped_stepper = ex.stepper.generic.DifficultyConvectionStepper(
            self.num_spatial_dims,
            self.num_points,
            linear_difficulties=substepped_gammas,
            # Need minus to move the convection to the right hand side
            convection_difficulty=-substepped_delta,
            conservative=self.conservative,
            order=self.order,
            dealiasing_fraction=self.dealiasing_fraction,
            num_circle_points=self.num_circle_points,
            circle_radius=self.circle_radius,
        )

        if self.num_substeps == 1:
            stepper = substepped_stepper
        else:
            stepper = ex.RepeatedStepper(substepped_stepper, self.num_substeps)

        return stepper

    def get_ref_stepper(self):
        return self._build_stepper(self.gammas, self.convection_delta)

    def get_coarse_stepper(self) -> ex.BaseStepper:
        return self._build_stepper(
            tuple(f * self.coarse_proportion for f in self.gammas),
            self.coarse_proportion * self.convection_delta,
        )

    def get_scenario_name(self) -> str:
        active_indices = []
        for i, a in enumerate(self.gammas):
            if a != 0.0:
                active_indices.append(i)
        return f"{self.num_spatial_dims}d_diff_conv_{'_'.join(str(i) for i in active_indices)}"
gammas class-attribute instance-attribute ¤
gammas: tuple[float, ...] = (0.0, 0.0, 1.5, 0.0, 0.0)
convection_delta class-attribute instance-attribute ¤
convection_delta: float = -1.5
num_substeps class-attribute instance-attribute ¤
num_substeps: int = 1
coarse_proportion class-attribute instance-attribute ¤
coarse_proportion: float = 0.5
order class-attribute instance-attribute ¤
order: int = 2
dealiasing_fraction class-attribute instance-attribute ¤
dealiasing_fraction: float = 2 / 3
num_circle_points class-attribute instance-attribute ¤
num_circle_points: float = 16
circle_radius class-attribute instance-attribute ¤
circle_radius: float = 1.0
__post_init__ ¤
__post_init__()
Source code in apebench/scenarios/difficulty/_convection.py
24
25
def __post_init__(self):
    self.num_channels = self.num_spatial_dims  # Overwrite
_build_stepper ¤
_build_stepper(gammas, delta)
Source code in apebench/scenarios/difficulty/_convection.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def _build_stepper(self, gammas, delta):
    substepped_gammas = tuple(g / self.num_substeps for g in gammas)
    substepped_delta = delta / self.num_substeps

    substepped_stepper = ex.stepper.generic.DifficultyConvectionStepper(
        self.num_spatial_dims,
        self.num_points,
        linear_difficulties=substepped_gammas,
        # Need minus to move the convection to the right hand side
        convection_difficulty=-substepped_delta,
        conservative=self.conservative,
        order=self.order,
        dealiasing_fraction=self.dealiasing_fraction,
        num_circle_points=self.num_circle_points,
        circle_radius=self.circle_radius,
    )

    if self.num_substeps == 1:
        stepper = substepped_stepper
    else:
        stepper = ex.RepeatedStepper(substepped_stepper, self.num_substeps)

    return stepper
get_ref_stepper ¤
get_ref_stepper()
Source code in apebench/scenarios/difficulty/_convection.py
51
52
def get_ref_stepper(self):
    return self._build_stepper(self.gammas, self.convection_delta)
get_coarse_stepper ¤
get_coarse_stepper() -> ex.BaseStepper
Source code in apebench/scenarios/difficulty/_convection.py
54
55
56
57
58
def get_coarse_stepper(self) -> ex.BaseStepper:
    return self._build_stepper(
        tuple(f * self.coarse_proportion for f in self.gammas),
        self.coarse_proportion * self.convection_delta,
    )
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/difficulty/_convection.py
60
61
62
63
64
65
def get_scenario_name(self) -> str:
    active_indices = []
    for i, a in enumerate(self.gammas):
        if a != 0.0:
            active_indices.append(i)
    return f"{self.num_spatial_dims}d_diff_conv_{'_'.join(str(i) for i in active_indices)}"