Core API Reference¶
The opifex.core package provides the fundamental abstractions and interfaces for the Opifex framework.
Problems¶
The Problem interface is defined as a Protocol, serving as the unified contract for all scientific machine learning problems.
Problem Protocol¶
opifex.core.problems.Problem
¶
PDE Problems¶
opifex.core.problems.PDEProblem
¶
PDEProblem(geometry: Geometry, equation: Callable, boundary_conditions: dict[str, Any] | list[Any], initial_conditions: dict[str, Any] | list[Any] | None = None, parameters: dict[str, float] | None = None, time_dependent: bool = False)
Bases: ABC
Base class for Partial Differential Equation problems.
This class provides the foundation for defining PDE problems that can be solved using Physics-Informed Neural Networks (PINNs) or Neural Operators.
Source code in opifex/core/problems.py
ODE Problems¶
opifex.core.problems.ODEProblem
¶
ODEProblem(time_span: tuple[float, float], equation: Callable, initial_conditions: dict[str, float | Array] | None = None, boundary_conditions: dict[str, Any] | None = None, parameters: dict[str, float] | None = None)
Bases: ABC
Base class for Ordinary Differential Equation problems.
Supports both initial value problems (IVPs) and boundary value problems (BVPs).
Source code in opifex/core/problems.py
Optimization Problems¶
opifex.core.problems.OptimizationProblem
¶
OptimizationProblem(dimension: int, bounds: list[tuple[float, float]] | None = None, constraints: list[Callable] | None = None, parameters: dict[str, Any] | None = None)
Bases: ABC
Base class for optimization problems.
Supports both constrained and unconstrained optimization, with support for learn-to-optimize (L2O) applications.
Source code in opifex/core/problems.py
Quantum Problems¶
opifex.core.problems.QuantumProblem
¶
QuantumProblem(molecular_system: MolecularSystem, method: str = 'neural_dft', convergence_threshold: float = 1e-08, max_iterations: int = 100, parameters: dict[str, Any] | None = None)
Bases: ABC
Base class for quantum mechanical problems.
This class provides the foundation for quantum mechanical calculations, including electronic structure, molecular dynamics, and quantum chemistry.
Source code in opifex/core/problems.py
get_geometry
¶
get_domain
¶
Get quantum mechanical domain.
Source code in opifex/core/problems.py
get_parameters
¶
Get quantum mechanical parameters.
compute_energy
abstractmethod
¶
opifex.core.problems.ElectronicStructureProblem
¶
ElectronicStructureProblem(molecular_system: MolecularSystem, functional_type: str = 'neural_xc', scf_method: str = 'neural_scf', grid_level: int = 3, neural_functional_path: str | None = None, boundary_conditions: list[Any] | None = None, constraints: list[Any] | None = None, **kwargs)
Bases: QuantumProblem
Electronic structure calculation problem for Neural DFT.
This class specifically handles electronic structure calculations using neural density functional theory, including neural exchange-correlation functionals and ML-accelerated SCF methods.
Source code in opifex/core/problems.py
get_parameters
¶
Get Neural DFT specific parameters.
Source code in opifex/core/problems.py
validate
¶
validate() -> bool
Validate Neural DFT problem definition.
Source code in opifex/core/problems.py
compute_energy
¶
Compute total electronic energy using Neural DFT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
density
|
Array | None
|
Electronic density (if available from previous SCF iteration) |
None
|
Returns:
| Type | Description |
|---|---|
float | Array
|
Total electronic energy in Hartree (float or Array for AD compatibility) |
Source code in opifex/core/problems.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | |
compute_forces
¶
Compute forces on nuclei using JAX automatic differentiation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
density
|
Array | None
|
Electronic density |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Forces on nuclei in Hartree/Bohr |
Source code in opifex/core/problems.py
setup_neural_functional
¶
Setup neural exchange-correlation functional.
Source code in opifex/core/problems.py
setup_scf_cycle
¶
Setup Self-Consistent Field cycle parameters.
Source code in opifex/core/problems.py
Factory Functions¶
Boundary Conditions¶
Base Classes¶
Bases: ABC
Abstract base class for boundary conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundary
|
str
|
Boundary identifier (e.g., "left", "right", "top", "bottom") |
required |
time_dependent
|
bool
|
Whether condition varies with time |
False
|
spatial_dependent
|
bool
|
Whether condition varies with spatial position |
True
|
Initial condition specification for time-dependent problems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float | Callable[[Array], Array]
|
Constant value or function defining initial condition |
required |
dimension
|
int
|
Dimension of the solution field |
1
|
derivative_order
|
int
|
Order of time derivative (0=position, 1=velocity, etc.) |
0
|
name
|
str | None
|
Optional name for the initial condition |
None
|
Classical Boundary Conditions¶
Bases: BoundaryCondition
Dirichlet boundary condition: u = g on boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundary
|
str
|
Boundary identifier |
required |
value
|
float | Callable[..., Array]
|
Constant value or function g(x) or g(x, t) for boundary |
required |
time_dependent
|
bool
|
Whether condition varies with time |
False
|
evaluate
¶
Evaluate Dirichlet condition at given position and time.
apply
¶
apply(params: Array, x: Array | None = None, t: float = 0.0, weight: float = 1.0, **kwargs: Any) -> Array
Apply Dirichlet boundary condition to parameters.
This method bridges the OOP boundary specification with the functional boundary application system, allowing BC objects to apply themselves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Array
|
Parameter array to constrain |
required |
x
|
Array | None
|
Optional spatial coordinates for function evaluation |
None
|
t
|
float
|
Time for time-dependent conditions |
0.0
|
weight
|
float
|
Constraint weight (0-1, default 1.0) |
1.0
|
**kwargs
|
Any
|
Additional arguments (left_boundary, right_boundary) |
{}
|
Returns:
| Type | Description |
|---|---|
Array
|
Parameters with Dirichlet boundary condition applied |
Examples:
Bases: BoundaryCondition
Neumann boundary condition: du/dn = g on boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundary
|
str
|
Boundary identifier |
required |
value
|
float | Callable[..., Array]
|
Constant value or function g(x) or g(x, t) for normal derivative |
required |
time_dependent
|
bool
|
Whether condition varies with time |
False
|
evaluate
¶
Evaluate Neumann condition at given position and time.
apply
¶
Apply Neumann boundary condition to parameters.
This method bridges the OOP boundary specification with the functional boundary application system, allowing BC objects to apply themselves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Array
|
Parameter array to constrain |
required |
x
|
Array | None
|
Optional spatial coordinates (unused for Neumann, kept for interface consistency) |
None
|
t
|
float
|
Time for time-dependent conditions (unused for Neumann, kept for interface consistency) |
0.0
|
weight
|
float
|
Constraint weight (0-1, default 1.0) |
1.0
|
Returns:
| Type | Description |
|---|---|
Array
|
Parameters with Neumann boundary condition applied (zero derivative) |
Examples:
Bases: BoundaryCondition
Robin (mixed) boundary condition: alpha*u + beta*du/dn = gamma on boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundary
|
str
|
Boundary identifier |
required |
alpha
|
float | Callable[..., float]
|
Coefficient for u term |
required |
beta
|
float | Callable[..., float]
|
Coefficient for du/dn term |
required |
gamma
|
float | Callable[..., Array]
|
Right-hand side function |
required |
time_dependent
|
bool
|
Whether condition varies with time |
False
|
evaluate
¶
Evaluate Robin condition coefficients and RHS at given position and time.
apply
¶
Apply Robin boundary condition to parameters.
This method bridges the OOP boundary specification with the functional boundary application system, allowing BC objects to apply themselves.
Robin condition: alpha*u + beta*du/dn = gamma on boundary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Array
|
Parameter array to constrain |
required |
x
|
Array | None
|
Optional spatial coordinates for function evaluation |
None
|
t
|
float
|
Time for time-dependent conditions |
0.0
|
weight
|
float
|
Constraint weight (0-1, default 1.0) |
1.0
|
Returns:
| Type | Description |
|---|---|
Array
|
Parameters with Robin boundary condition applied |
Examples:
Quantum Boundary Conditions & Constraints¶
Bases: BoundaryCondition
Quantum mechanical wavefunction boundary conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_type
|
str
|
Type of wavefunction condition ("vanishing", "normalization", "periodic", "boundary") |
required |
boundary
|
str
|
Boundary identifier for spatial boundaries |
'all'
|
value
|
complex | None
|
Value for boundary conditions (real values auto-converted to complex) |
None
|
norm_value
|
float | None
|
Normalization value for wavefunction |
None
|
Bases: Constraint
Electronic density constraints for quantum systems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraint_type
|
str
|
Type of constraint ("conservation", "positivity", "particle_number") |
required |
n_electrons
|
int | None
|
Number of electrons for particle number conservation |
None
|
tolerance
|
float
|
Tolerance for constraint satisfaction |
1e-08
|
enforcement_method
|
str
|
Method for constraint enforcement |
'lagrange'
|
Bases: Constraint
Molecular symmetry constraints for quantum systems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point_group
|
str | None
|
Point group symmetry (e.g., "C2v", "D2h") |
None
|
operations
|
Sequence[str] | None
|
List of symmetry operations |
None
|
symmetry_type
|
str
|
Type of symmetry ("point_group", "translational") |
'point_group'
|
lattice_vectors
|
Array | None
|
Lattice vectors for periodic systems |
None
|
enforce_in_loss
|
bool
|
Whether to enforce symmetry in loss function |
True
|
Collections¶
Collection and management of boundary conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundary_conditions
|
Sequence[BoundaryCondition]
|
List of boundary conditions |
required |
get_boundary_condition
¶
get_boundary_condition(boundary: str) -> BoundaryCondition | None
Get boundary condition for specific boundary.
get_by_type
¶
get_by_type(condition_type: str) -> list[BoundaryCondition]
Get all boundary conditions of specific type.
remove_condition
¶
Remove boundary condition for specific boundary.
apply_all
¶
Apply all boundary conditions in collection to parameters.
This method sequentially applies each boundary condition in the collection, allowing multiple BCs to be enforced together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Array
|
Parameter array to constrain |
required |
x
|
Array | None
|
Optional spatial coordinates for function evaluation |
None
|
t
|
float
|
Time for time-dependent conditions |
0.0
|
weight
|
float
|
Global constraint weight applied to all BCs (0-1, default 1.0) |
1.0
|
Returns:
| Type | Description |
|---|---|
Array
|
Parameters with all boundary conditions applied |
Examples: