### Install Python Dependencies Source: https://github.com/nvidia/physicsnemo-sym/blob/main/examples/reservoir_simulation/3D/README.md Installs the required Python packages listed in the 'requirements.txt' file. This is typically done within the specific example's directory, such as the 3D reservoir simulation example. ```bash cd /examples/physicsnemo-sym/examples/reservoir_simulation/3D/ pip install -r requirements.txt ``` -------------------------------- ### Setup Tensorboard (Bare Metal) Source: https://github.com/nvidia/physicsnemo-sym/blob/main/examples/reservoir_simulation/Norne/README.md Activates the MDLO conda environment, navigates to the src directory, and starts the Tensorboard visualization server on port 7007. This command is used to monitor training and validation losses during experiments. ```bash conda activate MDLO cd src tensorboard --logdir=./ --port=7007 ``` -------------------------------- ### Start Tensorboard for Visualization Source: https://github.com/nvidia/physicsnemo-sym/blob/main/docs/user_guide/basics/lid_driven_cavity_flow.rst Launches Tensorboard to visualize training and validation losses. This command should be run in a separate terminal within the example's working directory, specifying the log directory and a port. ```bash tensorboard --logdir=./ --port=7007 ``` -------------------------------- ### Load and Configure Domain for PDE Solver Source: https://github.com/nvidia/physicsnemo-sym/blob/main/docs/user_guide/basics/lid_driven_cavity_flow.rst Illustrates loading a 2D LDC example configuration and setting up the Domain object, which includes the PDE, boundary conditions, Validator, and Inferencer. This is a foundational step for setting up the solver. ```python from physics_nemo_sym.domain import Domain config = { "pde": pde, "boundary_conditions": bc, "validator": validator, "inferencer": inferencer, } domain = Domain(config) ``` -------------------------------- ### Install AMGX and pyAMGX within Docker Container Source: https://github.com/nvidia/physicsnemo-sym/blob/main/examples/reservoir_simulation/GenAI_workflows/2D/README.md Execute these commands inside the running PhysicsNeMo-Sym Docker container to install the AMGX solver and its Python wrapper. This is a one-time setup process. ```bash # Install AMGX (only once!) cd /workspace ./install_amgx.sh ./install_pyamgx.sh cd ./project ``` -------------------------------- ### Install Dependencies with Pip Source: https://github.com/nvidia/physicsnemo-sym/blob/main/examples/test/README.md Installs required Python libraries: quadpy, GPUtil, and gdown. These are necessary for running experiments and checking convergence. ```bash pip install quadpy GPUtil gdown ``` -------------------------------- ### PhysicsNeMo Sym Configuration Example Source: https://github.com/nvidia/physicsnemo-sym/blob/main/docs/user_guide/basics/lid_driven_cavity_flow.rst An example of a PhysicsNeMo Sym configuration file in YAML format. This file defines various parameters for the simulation, including neural network architecture details and other settings, demonstrating the use of Hydra for configuration. ```yaml arch: fully_connected: layers: 6 neurons: 512 nonlinearity: swish optimizer: name: adam lr: 0.001 logging: frequency: 100 callbacks: early_stopping: monitor: val_loss patience: 10 ``` -------------------------------- ### Launch PhysicsNeMo Container Source: https://github.com/nvidia/physicsnemo-sym/blob/main/examples/reservoir_simulation/3D/README.md Launches the PhysicsNeMo container with necessary configurations for development and testing. It mounts the current directory to /examples and sets resource limits. This command is essential for running the project's examples. ```bash docker run --rm --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 --runtime nvidia -v ${PWD}:/examples -it nvcr.io/nvidia/physicsnemo/physicsnemo:23.08 ``` -------------------------------- ### Start PhysicsNemo Solver Source: https://github.com/nvidia/physicsnemo-sym/blob/main/docs/user_guide/notebook/notebook.ipynb Initiates the solver for the PhysicsNemo simulation. This function call is the primary method to begin the simulation process. ```python slv.solve() ``` -------------------------------- ### Run Experiments with Python Source: https://github.com/nvidia/physicsnemo-sym/blob/main/examples/test/README.md Launches and trains examples to test convergence and generate reports. Requires 'mode' and 'gpus' to be specified. Modes include 'full', 'single_step', and 'unit_tests'. ```bash python run_experiments.py --mode=unit_tests --gpus=0,1 ``` -------------------------------- ### Setup TensorBoard for Visualization Source: https://github.com/nvidia/physicsnemo-sym/blob/main/examples/reservoir_simulation/3D/README.md Launches TensorBoard to visualize training and validation losses. This command is run from the working directory of the forward problem, specifying a port for access. It helps in monitoring the machine learning experiment progress. ```bash cd src tensorboard --logdir=./ --port=7007 ``` -------------------------------- ### Run Doctest for Docstring Examples (Bash) Source: https://github.com/nvidia/physicsnemo-sym/blob/main/CONTRIBUTING.md This command uses pytest to run doctests, which are examples embedded within the docstrings of Python code. It ensures that these examples are correct and produce the expected output, validating the documentation and the code's behavior as described. This is crucial for maintaining accurate and functional examples. ```bash pytest --doctest-modules ``` -------------------------------- ### Install and Use Pre-commit Hooks Source: https://github.com/nvidia/physicsnemo-sym/blob/main/CONTRIBUTING.md This code demonstrates the installation and activation of pre-commit hooks for the PhysicsNeMo project. Pre-commit is required to ensure code quality and compatibility with the CI pipeline. Once installed, hooks automatically run on commits, checking for formatting and other standards. ```bash pip install pre-commit pre-commit install ``` -------------------------------- ### Set up Tensorboard for Visualization (Bash) Source: https://github.com/nvidia/physicsnemo-sym/blob/main/examples/reservoir_simulation/CCUS/README.md Instructions for setting up Tensorboard to visualize machine learning experiment results. This involves activating a conda environment, navigating to the source directory, and running the tensorboard command with a specified log directory and port. It is applicable for both bare metal and Docker environments. ```bash conda activate MDLO cd src tensorboard --logdir=./ --port=7007 ``` ```bash cd src tensorboard --logdir=./ --port=7007 ``` -------------------------------- ### Define Inferencer for 3D Dielectric Slab Waveguide in Python Source: https://github.com/nvidia/physicsnemo-sym/blob/main/docs/user_guide/intermediate/em.rst This Python code defines the inferencer for the 3D dielectric slab waveguide simulation, specifying the domain bounds. This is the final setup step in the slab_3D.py example, preceding the simulation execution. ```python from physicsnemo.examples.waveguide.slab_3D.slab_3D import * # Finally, define the inferencer. These are # same as the previous example except the bounds for the domain. inferencer = Inferencer(model=model, bounds=[[0, 1], [0, 1], [0, 1]]) ``` -------------------------------- ### Install PhysicsNeMo-Sym using pip Source: https://github.com/nvidia/physicsnemo-sym/blob/main/examples/reservoir_simulation/GenAI_workflows/2D/README.md This command installs the PhysicsNeMo-Sym package using pip. Ensure you have Python and pip installed and are in the correct environment. ```bash pip install nvidia-physicsnemo.sym ``` -------------------------------- ### Compare Surrogate and NVRS (Docker) Source: https://github.com/nvidia/physicsnemo-sym/blob/main/examples/reservoir_simulation/Norne/README.md Downloads and unzips necessary data, copies files, navigates to the src directory, and executes the Compare_FVM_Surrogate.py script to compare PINO surrogate solutions with the NVRS finite volume simulator within a Docker container. Assumes the environment is already set up. ```bash wget --content-disposition https://api.ngc.nvidia.com/v2/resources/nvidia/modulus/Modulus_reservoir_simulation_supplemental_material/versions/0.1/zip -O modulus_reservoir_simulation_supplemental_material_0.1.zip unzip modulus_reservoir_simulation_supplemental_material_0.1.zip unzip modulus_reservoir_simulation_norne_supplemental_material.zip cp -r modulus_reservoir_simulation_norne_supplemental_material/* . cd src python Compare_FVM_Surrogate.py cd .. ``` -------------------------------- ### Install PhysicsNeMo v23.09 (Bash) Source: https://github.com/nvidia/physicsnemo-sym/blob/main/examples/reservoir_simulation/CCUS/README.md Installs the PhysicsNeMo v23.09 package using pip. This is a prerequisite for using the PhysicsNeMo library on a bare-metal system. ```bash pip install nvidia-physicsnemo.sym ``` -------------------------------- ### Set up Domain, Solver, Validators, and Inferencers in Python Source: https://context7.com/nvidia/physicsnemo-sym/llms.txt Illustrates how to aggregate constraints into a Domain, and then use the Solver for the training loop. It also shows how to add PointwiseValidator for comparing with reference solutions and PointwiseInferencer for visualization. ```python import physicsnemo.sym from physicsnemo.sym.solver import Solver from physicsnemo.sym.domain import Domain from physicsnemo.sym.hydra import PhysicsNeMoConfig, instantiate_arch from physicsnemo.sym.domain.validator import PointwiseValidator from physicsnemo.sym.domain.inferencer import PointwiseInferencer import numpy as np @physicsnemo.sym.main(config_path="conf", config_name="config") def run(cfg: PhysicsNeMoConfig) -> None: # Create domain to hold all constraints domain = Domain() # Add boundary constraints domain.add_constraint(top_wall_bc, name="top_wall") domain.add_constraint(no_slip_bc, name="no_slip") # Add interior PDE constraint domain.add_constraint(interior_pde, name="interior") # Add validator for comparison with reference solution reference_data = { "x": np.random.uniform(-0.05, 0.05, (1000, 1)), "y": np.random.uniform(-0.05, 0.05, (1000, 1)) } reference_solution = {"u": np.zeros((1000, 1)), "v": np.zeros((1000, 1))} validator = PointwiseValidator( nodes=nodes, invar=reference_data, true_outvar=reference_solution, batch_size=1024 ) domain.add_validator(validator, name="reference_comparison") # Add inferencer for visualization inferencer = PointwiseInferencer( nodes=nodes, invar=reference_data, output_names=["u", "v", "p"], batch_size=1024 ) domain.add_inferencer(inferencer, name="field_inference") # Create and run solver solver = Solver(cfg, domain) solver.solve() if __name__ == "__main__": run() ``` -------------------------------- ### Run PINO Forward Problem (Docker) Source: https://github.com/nvidia/physicsnemo-sym/blob/main/examples/reservoir_simulation/Norne/README.md Downloads supplemental materials, unzips them, copies files, navigates to the src directory, and runs the Forward_problem_PINO.py and Learn_CCR.py scripts for the forward problem simulation within a Docker container. Assumes the environment is already set up. ```bash wget --content-disposition https://api.ngc.nvidia.com/v2/resources/nvidia/modulus/Modulus_reservoir_simulation_supplemental_material/versions/0.1/zip -O modulus_reservoir_simulation_supplemental_material_0.1.zip unzip modulus_reservoir_simulation_supplemental_material_0.1.zip unzip modulus_reservoir_simulation_norne_supplemental_material.zip cp -r modulus_reservoir_simulation_norne_supplemental_material/* . cd src python Forward_problem_PINO.py python Learn_CCR.py cd .. ``` -------------------------------- ### Configure LDC 2D Example in Python Source: https://github.com/nvidia/physicsnemo-sym/blob/main/docs/user_guide/basics/lid_driven_cavity_flow.rst This Python code configures the Lid-Driven Cavity (LDC) 2D example using PhysicsNeMo Sym. It sets up boundary conditions, interior point constraints, and loss weighting for the continuity and momentum equations. ```python import numpy as np import modulus from modulus.eq.pdes.navier_stokes import NavierStokes from modulus.geometry.primitives import Rectangle from modulus.key import Key from ldc_2d_problem import LDC2DProblem if __name__ == "__main__": # physics configuration ny = 128 nx = 128 batch_size = 1024 batch_per_epoch = 2 # geometry T = 1.0 x_max = 1.0 y_max = 1.0 lid_velocity = 1.0 # LDC problem ldc_problem = LDC2DProblem( x_max=x_max, y_max=y_max, lid_velocity=lid_velocity, T=T, n_x=nx, n_y=ny, batch_size=batch_size, batch_per_epoch=batch_per_epoch, ) # add geometry geo = Rectangle(Point((0, 0)), Point((x_max, y_max))) ldc_problem.add_geometry(geo) # add boundary conditions # bottom, left, right walls ldc_problem.add_boundary_constraint( modulus.pdes.BoundaryConstraint( nodes=ldc_problem.u_nodes, geometry=geo, alias="bottom_wall", addCriterion=( "x " + str(0.0) + " " + str(x_max) + " " + "y " + str(0.0) + " " + str(0.0) ), ) ) ldc_problem.add_boundary_constraint( modulus.pdes.BoundaryConstraint( nodes=ldc_problem.u_nodes, geometry=geo, alias="left_wall", addCriterion=( "x " + str(0.0) + " " + str(0.0) + " " + "y " + str(0.0) + " " + str(y_max) ), ) ) ldc_problem.add_boundary_constraint( modulus.pdes.BoundaryConstraint( nodes=ldc_problem.u_nodes, geometry=geo, alias="right_wall", addCriterion=( "x " + str(x_max) + " " + str(x_max) + " " + "y " + str(0.0) + " " + str(y_max) ), ) ) # top wall ldc_problem.add_boundary_constraint( modulus.pdes.BoundaryConstraint( nodes=ldc_problem.u_nodes, geometry=geo, alias="top_wall", addCriterion=( "x " + str(0.0) + " " + str(x_max) + " " + "y " + str(y_max) + " " + str(y_max) ), target_vars={"u": lid_velocity}, ) ) # add interior constraint ldc_problem.add_interior_constraint( modulus.pdes.InteriorConstraint( nodes=ldc_problem.interior_nodes, geometry=geo, # Specify the equations to solve # The keys are the variable names, and the values are the desired residuals # For example, 'continuity': 0 means the continuity equation should have a residual of 0 outvar={ "continuity": 0.0, "momentum_x": 0.0, "momentum_y": 0.0, }, # Specify the weighting for the loss function # This example uses the Signed Distance Field (SDF) to weight points further from the boundary more heavily lambda_weighting={Key("x"): lambda x: 1.0 - 20.0 * abs(x), Key("y"): lambda y: 1.0 - 20.0 * abs(y)}, ) ) # launch ldc_problem.solve() ```