Skip to content

Commit

Permalink
added pytest to requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuriyzabegaev committed Dec 13, 2023
1 parent c2e8841 commit f2bda56
Show file tree
Hide file tree
Showing 12 changed files with 2,242 additions and 509 deletions.
40 changes: 0 additions & 40 deletions .github/workflows/pytest.yml

This file was deleted.

113 changes: 67 additions & 46 deletions examples/1/results_1_poro.ipynb

Large diffs are not rendered by default.

766 changes: 766 additions & 0 deletions examples/1/results_1_thermal copy.ipynb

Large diffs are not rendered by default.

78 changes: 32 additions & 46 deletions examples/1/results_1_thermal.ipynb

Large diffs are not rendered by default.

1,696 changes: 1,349 additions & 347 deletions examples/4/results_4_thermal.ipynb

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions examples/mandel_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def get_fixed_stress_stabilization(self, l_factor: float) -> csr_matrix:

density = (
porepy_setup.fluid_density(subdomains)
.evaluate(porepy_setup.equation_system)
.val
.value(porepy_setup.equation_system)
)
diagonal_approx *= density

Expand Down
2 changes: 1 addition & 1 deletion examples/porepy_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _compute_cfl(self):
setup = self.porepy_setup
subdomains = setup.mdg.subdomains()
velosity = setup.darcy_flux(subdomains) / setup.fluid_viscosity(subdomains)
velosity = velosity.evaluate(setup.equation_system).val
velosity = velosity.value(setup.equation_system)
length = setup.mdg.subdomains()[0].face_areas
time_step = setup.time_manager.dt
CFL = velosity * time_step / length
Expand Down
42 changes: 16 additions & 26 deletions examples/thermal_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ def after_nonlinear_convergence(
self, solution: np.ndarray, errors: float, iteration_counter: int
) -> None:
subdomains = self.mdg.subdomains()
visc = self.fluid_viscosity(subdomains).evaluate(self.equation_system).val
dens = self.fluid_density(subdomains).evaluate(self.equation_system).val
visc = self.fluid_viscosity(subdomains).value(self.equation_system)
dens = self.fluid_density(subdomains).value(self.equation_system)
print(f"visc min: {visc.min()}, max: {visc.max()}")
print(f"rho min: {dens.min()}, max: {dens.max()}")
super().after_nonlinear_convergence(solution, errors, iteration_counter)
Expand All @@ -273,7 +273,7 @@ class ThermalSource(ThermalBase):
KEY_FLUID_SOURCE = "key_fluid_source"

def get_inlet_cells(self, sd: pp.Grid):
source_location: int = self.params['source_location']
source_location: int = self.params["source_location"]
if source_location == 0:
# high-perm region
x_inj = 265
Expand All @@ -288,13 +288,13 @@ def get_inlet_cells(self, sd: pp.Grid):
return loc

def get_outlet_cells(self, sd: pp.Grid):
source_location: int = self.params['source_location']
source_location: int = self.params["source_location"]
if source_location == 0:
x_inj = 140.0
y_inj = 210.0
elif source_location == 1:
x_inj = 140.
y_inj = 100.
x_inj = 140.0
y_inj = 100.0
else:
raise ValueError
x, y, _ = sd.cell_centers
Expand Down Expand Up @@ -640,15 +640,11 @@ def __init__(self, porepy_setup: ThermalSetup):

def compute_peclet(self):
model = self.porepy_setup
fourier_flux = (
model.fourier_flux(model.mdg.subdomains())
.evaluate(model.equation_system)
.val
fourier_flux = model.fourier_flux(model.mdg.subdomains()).value(
model.equation_system
)
enthalpy_flux = (
model.enthalpy_flux(model.mdg.subdomains())
.evaluate(model.equation_system)
.val
enthalpy_flux = model.enthalpy_flux(model.mdg.subdomains()).value(
model.equation_system
)
fourier_flux = np.maximum(fourier_flux, 1e-10)
peclet_max = abs(enthalpy_flux / fourier_flux).max()
Expand All @@ -658,13 +654,9 @@ def compute_peclet(self):
def compute_cfl(self):
setup = self.porepy_setup
velosity = (
(
setup.darcy_flux(setup.mdg.subdomains())
/ setup.fluid_viscosity_formula(422)
)
.evaluate(setup.equation_system)
.val
)
setup.darcy_flux(setup.mdg.subdomains())
/ setup.fluid_viscosity_formula(422)
).value(setup.equation_system)
length = setup.mdg.subdomains()[0].face_areas
time_step = setup.time_manager.dt
CFL = velosity * time_step / length
Expand All @@ -679,14 +671,12 @@ def compute_source_rate(self):
outlet_cells = setup.get_outlet_cells(subdomains[0])
inlet_rate = (
setup.fluid_rate_inlet(subdomains)
.evaluate(setup.equation_system)
.val[inlet_cells]
.value(setup.equation_system)[inlet_cells]
.max()
)
outlet_rate = (
setup.fluid_rate_outlet(subdomains)
.evaluate(setup.equation_system)
.val[outlet_cells]
.value(setup.equation_system)[outlet_cells]
.min()
)
sin_factor = setup.well_on
Expand Down Expand Up @@ -746,7 +736,7 @@ def get_primary_secondary_indices(
raise ValueError(f"{primary_variable=}")

def get_schur_cd_approximation(self, indices: np.ndarray):
schur_ad = self.porepy_setup.schur_ad.evaluate(
schur_ad = self.porepy_setup.schur_ad.value_and_jacobian(
self.porepy_setup.equation_system
)
return schur_ad.jac[:, indices]
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
numpy
scipy
scikit-learn
pyamg
pyamg
pytest
4 changes: 4 additions & 0 deletions src/solver_selector/solver_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,15 @@ def make_solver_selector(
)

load_statistics_paths: Sequence[str]
data: Sequence[SolverSelectionData]
if load_statistics_paths := params.get("load_statistics_paths", None):
print("Warm start using data:")
for path in load_statistics_paths:
print(path)
data = load_data(load_statistics_paths)
solver_selector.learn_performance_offline(selection_dataset=data)

if data := params.get("load_statistics", None):
solver_selector.learn_performance_offline(selection_dataset=data)

return solver_selector
1 change: 1 addition & 0 deletions src/solver_selector/solver_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ def _parse_config_recursively(
self, config: dict
) -> tuple[dict[int, str], dict[int, dict[str, number]]]:
decision = config
assert isinstance(decision, str)
assert decision in self.options
return {self._id: decision}, {}

Expand Down
3 changes: 3 additions & 0 deletions tests/test_performance_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ def test_parameters_space():
{
"predictor": "eps_greedy",
"regressor": "gradient_boosting",
'exploration': 0,
},
{
"predictor": "eps_greedy",
"regressor": "mlp",
'exploration': 0,
'samples_before_fit': 10,
},
{
"predictor": "gaussian_process",
Expand Down

0 comments on commit f2bda56

Please sign in to comment.