Skip to content

Generic Scenarios in normalized Mode¤

apebench.scenarios.normalized.Linear ¤

Bases: BaseScenario

Source code in apebench/scenarios/normalized/_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
30
31
class Linear(BaseScenario):
    alphas: tuple[float, ...] = (0.0, -0.025, 0.0, 0.0, 0.0)
    coarse_proportion: float = 0.5

    def get_ref_stepper(self):
        return ex.stepper.generic.NormalizedLinearStepper(
            num_spatial_dims=self.num_spatial_dims,
            num_points=self.num_points,
            normalized_linear_coefficients=self.alphas,
        )

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

    def get_scenario_name(self) -> str:
        active_indices = []
        for i, a in enumerate(self.alphas):
            if a != 0.0:
                active_indices.append(i)
        return f"{self.num_spatial_dims}d_norm_lin_{'_'.join(str(i) for i in active_indices)}"
alphas class-attribute instance-attribute ¤
alphas: tuple[float, ...] = (0.0, -0.025, 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/normalized/_linear.py
26
27
28
29
30
31
def get_scenario_name(self) -> str:
    active_indices = []
    for i, a in enumerate(self.alphas):
        if a != 0.0:
            active_indices.append(i)
    return f"{self.num_spatial_dims}d_norm_lin_{'_'.join(str(i) for i in active_indices)}"

apebench.scenarios.normalized.LinearSimple ¤

Bases: Linear

Source code in apebench/scenarios/normalized/_linear.py
34
35
36
37
38
39
class LinearSimple(Linear):
    linear_alpha: float = -0.025
    linear_term_order: int = 1

    def __post_init__(self):
        self.alphas = (0.0,) * self.linear_term_order + (self.linear_alpha,)
linear_alpha class-attribute instance-attribute ¤
linear_alpha: float = -0.025
linear_term_order class-attribute instance-attribute ¤
linear_term_order: int = 1
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/normalized/_linear.py
26
27
28
29
30
31
def get_scenario_name(self) -> str:
    active_indices = []
    for i, a in enumerate(self.alphas):
        if a != 0.0:
            active_indices.append(i)
    return f"{self.num_spatial_dims}d_norm_lin_{'_'.join(str(i) for i in active_indices)}"

apebench.scenarios.normalized.FirstFour ¤

Bases: Linear

Source code in apebench/scenarios/normalized/_linear.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
class FirstFour(Linear):
    advection_alpha: float = -0.025
    diffusion_alpha: float = 8e-4
    dispersion_alpha: float = 2.5e-7
    hyp_diffusion_alpha: float = -7.5e-10

    def __post_init__(self):
        self.alphas = (
            0.0,
            self.advection_alpha,
            self.diffusion_alpha,
            self.dispersion_alpha,
            self.hyp_diffusion_alpha,
        )

    def get_scenario_name(self) -> str:
        return f"{self.num_spatial_dims}d_norm_four"
advection_alpha class-attribute instance-attribute ¤
advection_alpha: float = -0.025
diffusion_alpha class-attribute instance-attribute ¤
diffusion_alpha: float = 0.0008
dispersion_alpha class-attribute instance-attribute ¤
dispersion_alpha: float = 2.5e-07
hyp_diffusion_alpha class-attribute instance-attribute ¤
hyp_diffusion_alpha: float = -7.5e-10
__post_init__ ¤
__post_init__()
Source code in apebench/scenarios/normalized/_linear.py
 99
100
101
102
103
104
105
106
def __post_init__(self):
    self.alphas = (
        0.0,
        self.advection_alpha,
        self.diffusion_alpha,
        self.dispersion_alpha,
        self.hyp_diffusion_alpha,
    )
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/normalized/_linear.py
108
109
def get_scenario_name(self) -> str:
    return f"{self.num_spatial_dims}d_norm_four"

apebench.scenarios.normalized.Nonlinear ¤

Bases: BaseScenario

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

Source code in apebench/scenarios/normalized/_nonlinear.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
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
class Nonlinear(BaseScenario):
    """
    Uses the single channel convection mode to not have channels grow with
    spatial dimensions.
    """

    alphas: tuple[float, ...] = (0.0, 0.0, 0.00003, 0.0, 0.0)
    betas: tuple[float, float, float] = (0.0, -0.0125, 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, alphas, betas):
        substepped_alphas = tuple(a / self.num_substeps for a in alphas)
        substepped_betas = tuple(b / self.num_substeps for b in betas)

        substepped_stepper = ex.stepper.generic.NormalizedNonlinearStepper(
            num_spatial_dims=self.num_spatial_dims,
            num_points=self.num_points,
            normalized_linear_coefficients=substepped_alphas,
            normalized_nonlinear_coefficients=substepped_betas,
            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.alphas, self.betas)

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

    def get_scenario_name(self) -> str:
        return f"{self.num_spatial_dims}d_norm_nonlin"
alphas class-attribute instance-attribute ¤
alphas: tuple[float, ...] = (0.0, 0.0, 3e-05, 0.0, 0.0)
betas class-attribute instance-attribute ¤
betas: tuple[float, float, float] = (0.0, -0.0125, 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(alphas, betas)
Source code in apebench/scenarios/normalized/_nonlinear.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def _build_stepper(self, alphas, betas):
    substepped_alphas = tuple(a / self.num_substeps for a in alphas)
    substepped_betas = tuple(b / self.num_substeps for b in betas)

    substepped_stepper = ex.stepper.generic.NormalizedNonlinearStepper(
        num_spatial_dims=self.num_spatial_dims,
        num_points=self.num_points,
        normalized_linear_coefficients=substepped_alphas,
        normalized_nonlinear_coefficients=substepped_betas,
        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/normalized/_nonlinear.py
49
50
def get_ref_stepper(self):
    return self._build_stepper(self.alphas, self.betas)
get_coarse_stepper ¤
get_coarse_stepper()
Source code in apebench/scenarios/normalized/_nonlinear.py
52
53
54
55
56
def get_coarse_stepper(self):
    return self._build_stepper(
        tuple(f * self.coarse_proportion for f in self.alphas),
        tuple(f * self.coarse_proportion for f in self.betas),
    )
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/normalized/_nonlinear.py
58
59
def get_scenario_name(self) -> str:
    return f"{self.num_spatial_dims}d_norm_nonlin"

apebench.scenarios.normalized.Convection ¤

Bases: BaseScenario

Source code in apebench/scenarios/normalized/_convection.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
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
class Convection(BaseScenario):
    alphas: tuple[float, ...] = (0.0, 0.0, 3.0e-5, 0.0, 0.0)
    convection_beta: float = -1.25e-2
    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, convection, alphas):
        substepped_convection = convection / self.num_substeps
        substepped_alphas = tuple(a / self.num_substeps for a in alphas)

        substepped_stepper = ex.stepper.generic.NormalizedConvectionStepper(
            self.num_spatial_dims,
            self.num_points,
            normalized_linear_coefficients=substepped_alphas,
            # Need minus to move the convection to the right hand side
            normalized_convection_scale=-substepped_convection,
            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.convection_beta, self.alphas)

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

    def get_scenario_name(self) -> str:
        active_indices = []
        for i, a in enumerate(self.alphas):
            if a != 0.0:
                active_indices.append(i)
        return f"{self.num_spatial_dims}d_norm_conv_{'_'.join(str(i) for i in active_indices)}"
alphas class-attribute instance-attribute ¤
alphas: tuple[float, ...] = (0.0, 0.0, 3e-05, 0.0, 0.0)
convection_beta class-attribute instance-attribute ¤
convection_beta: float = -0.0125
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/normalized/_convection.py
20
21
def __post_init__(self):
    self.num_channels = self.num_spatial_dims  # Overwrite
_build_stepper ¤
_build_stepper(convection, alphas)
Source code in apebench/scenarios/normalized/_convection.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def _build_stepper(self, convection, alphas):
    substepped_convection = convection / self.num_substeps
    substepped_alphas = tuple(a / self.num_substeps for a in alphas)

    substepped_stepper = ex.stepper.generic.NormalizedConvectionStepper(
        self.num_spatial_dims,
        self.num_points,
        normalized_linear_coefficients=substepped_alphas,
        # Need minus to move the convection to the right hand side
        normalized_convection_scale=-substepped_convection,
        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/normalized/_convection.py
47
48
def get_ref_stepper(self):
    return self._build_stepper(self.convection_beta, self.alphas)
get_coarse_stepper ¤
get_coarse_stepper() -> ex.BaseStepper
Source code in apebench/scenarios/normalized/_convection.py
50
51
52
53
54
def get_coarse_stepper(self) -> ex.BaseStepper:
    return self._build_stepper(
        self.coarse_proportion * self.convection_beta,
        tuple(f * self.coarse_proportion for f in self.alphas),
    )
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/normalized/_convection.py
56
57
58
59
60
61
def get_scenario_name(self) -> str:
    active_indices = []
    for i, a in enumerate(self.alphas):
        if a != 0.0:
            active_indices.append(i)
    return f"{self.num_spatial_dims}d_norm_conv_{'_'.join(str(i) for i in active_indices)}"