Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 12 additions & 12 deletions epde/integrate/deepxde_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ def func(x):

if len(left_idx) > 0:
bcs.append(dde.icbc.DirichletBC(geomtime, make_bc_func(left_idx),
lambda _, on_boundary: on_boundary and np.isclose(_.x[0], x.min(),
lambda _, on_boundary: on_boundary and np.isclose(_[0], x.min(),
rtol=1e-5,
atol=eps_x),
component=var_idx))
component=var_idx)) # Заменил _.x[0] на _[0]
if len(right_idx) > 0:
bcs.append(dde.icbc.DirichletBC(geomtime, make_bc_func(right_idx),
lambda _, on_boundary: on_boundary and np.isclose(_.x[0], x.max(),
lambda _, on_boundary: on_boundary and np.isclose(_[0], x.max(),
rtol=1e-5,
atol=eps_x),
component=var_idx))
component=var_idx)) # Заменил _.x[0] на _[0]
if len(initial_idx) > 0:
bcs.append(dde.icbc.IC(geomtime, make_bc_func(initial_idx),
lambda _, on_initial: on_initial,
Expand Down Expand Up @@ -197,28 +197,28 @@ def func(x):

if len(x_min_idx) > 0:
bcs.append(dde.icbc.DirichletBC(geomtime, make_bc_func(x_min_idx),
lambda _, on_boundary: on_boundary and np.isclose(_.x[0], x.min(),
lambda _, on_boundary: on_boundary and np.isclose(_[0], x.min(),
rtol=1e-5,
atol=eps_x),
component=var_idx))
component=var_idx)) # Заменил _.x[0] на _[0]
if len(x_max_idx) > 0:
bcs.append(dde.icbc.DirichletBC(geomtime, make_bc_func(x_max_idx),
lambda _, on_boundary: on_boundary and np.isclose(_.x[0], x.max(),
lambda _, on_boundary: on_boundary and np.isclose(_[0], x.max(),
rtol=1e-5,
atol=eps_x),
component=var_idx))
component=var_idx)) # Заменил _.x[0] на _[0]
if len(y_min_idx) > 0:
bcs.append(dde.icbc.DirichletBC(geomtime, make_bc_func(y_min_idx),
lambda _, on_boundary: on_boundary and np.isclose(_.x[1], y.min(),
lambda _, on_boundary: on_boundary and np.isclose(_[1], y.min(),
rtol=1e-5,
atol=eps_y),
component=var_idx))
component=var_idx)) # Заменил _.x[1] на _[1]
if len(y_max_idx) > 0:
bcs.append(dde.icbc.DirichletBC(geomtime, make_bc_func(y_max_idx),
lambda _, on_boundary: on_boundary and np.isclose(_.x[1], y.max(),
lambda _, on_boundary: on_boundary and np.isclose(_[1], y.max(),
rtol=1e-5,
atol=eps_y),
component=var_idx))
component=var_idx)) # Заменил _.x[1] на _[1]
if len(initial_idx) > 0:
bcs.append(dde.icbc.IC(geomtime, make_bc_func(initial_idx),
lambda _, on_initial: on_initial,
Expand Down
84 changes: 84 additions & 0 deletions epde/solver/poka_tut_pobudem/wave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import numpy as np
import copy
from epde.interface.interface import EpdeSearch
from epde.interface.equation_translator import translate_equation
from epde.structure.main_structures import SoEq, Chromosome
from epde.interface.token_family import TFPool
from epde.operators.utils.default_parameter_loader import EvolutionaryParams
from epde.solver.factory import SolverFactory

def create_equation_from_str(eq_str, target_var, base_pool, all_vars):
families_copy = [copy.deepcopy(fam) for fam in base_pool.families]
for fam in families_copy:
if hasattr(fam, 'variable') and fam.variable is not None and fam.variable != target_var:
fam.status['demands_equation'] = False
temp_pool = TFPool(families_copy)
soeq = translate_equation(eq_str, temp_pool, all_vars=[target_var])
return soeq.vals[target_var]

def solve_with_solver(solver_type, solver_config, system, grids, data):
adapter = SolverFactory.create(solver_type, **solver_config)
solutions, loss = adapter.solve(system, grids, data)
return solutions, loss

# ----------------------------------------------------------------------
# Волновое уравнение (PDE) – только DeepXDE
# ----------------------------------------------------------------------
print("=" * 60)
print("Wave equation (PDE) – DeepXDE PINN solver")
print("=" * 60)

# Генерация данных (аналитическое решение)
nx, nt = 50, 50
x = np.linspace(0, 1, nx)
t = np.linspace(0, 2, nt)
X_grid, T_grid = np.meshgrid(t, x, indexing='ij')
exact = np.sin(np.pi * X_grid) * np.cos(np.pi * T_grid)
data_wave = exact + 0.01 * np.random.normal(size=exact.shape)

# Создание пула EPDE
search_wave = EpdeSearch(
use_solver=False,
coordinate_tensors=(T_grid, X_grid),
verbose_params={'show_iter_idx': False},
device='cpu'
)
search_wave.set_preprocessor(default_preprocessor_type='FD', preprocessor_kwargs={})
search_wave.create_pool(
data=data_wave,
variable_names=['u'],
max_deriv_order=(2, 2),
additional_tokens=[]
)

# Уравнение волновое
eq_str = '1.0 * d^2u/dx1^2{power: 1.0} = d^2u/dx0^2{power: 1.0}'
soeq_wave = translate_equation(eq_str, search_wave.pool, all_vars=['u'])
eq_wave = soeq_wave.vals['u']
eq_wave.main_var_to_explain = 'u'
eq_wave.weights_internal = np.ones(len(eq_wave.structure) - 1)
eq_wave.weights_internal_evald = True
eq_wave.weights_final_evald = True

system_wave = SoEq(search_wave.pool, {})
system_wave.vals = Chromosome({'u': eq_wave}, {})
system_wave.moeadd_set = True

# Конфигурация DeepXDE (увеличиваем параметры для PDE)
solver_config_deepxde = EvolutionaryParams().get_default_params_for_operator('DeepXDEBasedFitness')
solver_config_deepxde['num_domain'] = 2000
solver_config_deepxde['num_boundary'] = 500
solver_config_deepxde['num_initial'] = 500
solver_config_deepxde['epochs'] = 3000

solutions_wave, loss_wave = solve_with_solver(
"deepxde",
solver_config_deepxde,
system_wave,
[T_grid, X_grid],
[data_wave.flatten()]
)

soln_wave = solutions_wave[0].reshape(data_wave.shape)
print(f"Loss (RMSE): {loss_wave:.6f}")
print(f"Max error: {np.max(np.abs(soln_wave - exact)):.6f}")
6 changes: 4 additions & 2 deletions tests/functional/operator_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ def create(name: str, params: dict) -> CompoundOperator:
operator = SolverBasedFitness(list(params.keys()), objectives=[primary],
primary=primary, stability=Instability(),
backend='deepxde')
sparsity = LASSOSparsity()
coeff_calc = LinRegBasedCoeffsEquation()
#sparsity = LASSOSparsity()
#coeff_calc = LinRegBasedCoeffsEquation()
sparsity = map_operator_between_levels(LASSOSparsity(), 'gene level', 'chromosome level')
coeff_calc = map_operator_between_levels(LinRegBasedCoeffsEquation(), 'gene level', 'chromosome level')
else:
raise ValueError(f"Unknown operator: {name}")

Expand Down
Loading