From eda7ba974ef5c88cb6d1b26cd5cee8b8542993a4 Mon Sep 17 00:00:00 2001 From: N_T Date: Tue, 12 Aug 2025 09:23:18 +0200 Subject: [PATCH] phiflow 3.4 updates --- diffphys-code-burgers.ipynb | 2 +- diffphys-code-ns.ipynb | 6 +++--- overview-burgers-forw.ipynb | 4 ++-- overview-ns-forw.ipynb | 4 ++-- physgrad-code.ipynb | 10 +++++----- physicalloss-div.ipynb | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/diffphys-code-burgers.ipynb b/diffphys-code-burgers.ipynb index 8da5f1a..129f45a 100644 --- a/diffphys-code-burgers.ipynb +++ b/diffphys-code-burgers.ipynb @@ -32,7 +32,7 @@ }, "outputs": [], "source": [ - "!pip install --upgrade --quiet phiflow==3.1\n", + "!pip install --upgrade --quiet phiflow==3.4\n", "from phi.tf.flow import *\n", "\n", "N = 128\n", diff --git a/diffphys-code-ns.ipynb b/diffphys-code-ns.ipynb index a2d7f0b..81c6a94 100644 --- a/diffphys-code-ns.ipynb +++ b/diffphys-code-ns.ipynb @@ -86,7 +86,7 @@ }, "outputs": [], "source": [ - "!pip install --upgrade --quiet phiflow==3.1\n", + "!pip install --upgrade --quiet phiflow==3.4\n", "from phi.torch.flow import * \n", "import pylab # for visualizations later on" ] @@ -191,7 +191,7 @@ " smoke = advect.mac_cormack(smoke, velocity, dt=1) + INFLOW\n", " buoyancy_force = (smoke * (0, 1)).at(velocity)\n", " velocity = advect.semi_lagrangian(velocity, velocity, dt=1) + buoyancy_force\n", - " velocity, _ = fluid.make_incompressible(velocity)\n", + " velocity, _ = fluid.make_incompressible(velocity, [], Solve('CG', 1e-3, rank_deficiency=0, suppress=[phi.math.NotConverged]) )\n", " return smoke, velocity\n", "\n", "for _ in range(20):\n", @@ -214,7 +214,7 @@ "source": [ "The last image shows the state of the advected smoke fields after 20 simulation steps. The final smoke shape of simulation `[3]` with an inflow at `(16,5)`, with the straight plume on the far right, will be our **reference state** below. The initial velocity of the other three will be modified in the optimization procedure below to match this reference.\n", "\n", - "(As a small side note: phiflow tensors will keep track of their chain of operations using the backend they were created for. E.g. a tensor created with NumPy will keep using NumPy/SciPy operations unless a PyTorch or TensorFlow tensor is also passed to the same operation. Thus, it is a good idea to verify that tensors are using the right backend once in a while, e.g., via `GRID.values.default_backend`.)\n" + "(As a small side note: the incompressible solve above requires additional flags to prevent exceptions from the CG solver due to a lack of convergence. During optimizations and learning tasks like this one that can happen, and the rank deficiency and suppress parameters achieve that for the phiflow pressure solve. Also, phiflow tensors will keep track of their chain of operations using the backend they were created for. E.g. a tensor created with NumPy will keep using NumPy/SciPy operations unless a PyTorch or TensorFlow tensor is also passed to the same operation. Thus, it is a good idea to verify that tensors are using the right backend once in a while, e.g., via `GRID.values.default_backend`.)\n" ] }, { diff --git a/overview-burgers-forw.ipynb b/overview-burgers-forw.ipynb index d0c0851..72eae07 100644 --- a/overview-burgers-forw.ipynb +++ b/overview-burgers-forw.ipynb @@ -45,12 +45,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "Using phiflow version: 3.2.0\n" + "Using phiflow version: 3.4.0\n" ] } ], "source": [ - "!pip install --upgrade --quiet phiflow==3.2\n", + "!pip install --upgrade --quiet phiflow==3.4\n", "from phi.flow import *\n", "print(\"Using phiflow version: {}\".format(phi.__version__))" ] diff --git a/overview-ns-forw.ipynb b/overview-ns-forw.ipynb index 7a41348..d39ec1a 100644 --- a/overview-ns-forw.ipynb +++ b/overview-ns-forw.ipynb @@ -43,7 +43,7 @@ }, "outputs": [], "source": [ - "!pip install --upgrade --quiet phiflow==3.1\n", + "!pip install --upgrade --quiet phiflow==3.4\n", "#!pip install --upgrade --quiet git+https://github.com/tum-pbs/PhiFlow@develop\n", "\n", "from phi.flow import * # The Dash GUI is not supported on Google colab, ignore the warning\n", @@ -159,7 +159,7 @@ " buoyancy_force = (smoke * (0, buoyancy_factor)).at(velocity) # resamples smoke to velocity sample points\n", " velocity = advect.semi_lagrangian(velocity, velocity, dt) + dt * buoyancy_force\n", " velocity = diffuse.explicit(velocity, NU, dt)\n", - " velocity, pressure = fluid.make_incompressible(velocity)\n", + " velocity, pressure = fluid.make_incompressible(velocity, (), Solve('CG', 1e-3))\n", " return velocity, smoke, pressure\n", "\n", "velocity, smoke, pressure = step(velocity, smoke, None, dt=DT)\n", diff --git a/physgrad-code.ipynb b/physgrad-code.ipynb index abb7de3..98673ba 100644 --- a/physgrad-code.ipynb +++ b/physgrad-code.ipynb @@ -254,9 +254,9 @@ " signal_prior = 0.5\n", " expected_amp = 1. * kernel.shape.get_size('x') * inv_kernel # This can be measured\n", " signal_likelihood = math.exp(-0.5 * (abs(amp) / expected_amp) ** 2) * signal_prior # this can be NaN\n", - " signal_likelihood = math.where(math.isfinite(signal_likelihood), signal_likelihood, math.zeros_like(signal_likelihood))\n", + " signal_likelihood = math.where(math.is_finite(signal_likelihood), signal_likelihood, math.zeros_like(signal_likelihood))\n", " noise_likelihood = math.exp(-0.5 * (abs(amp) / f_uncertainty) ** 2) * (1 - signal_prior)\n", - " probability_signal = math.divide_no_nan(signal_likelihood, (signal_likelihood + noise_likelihood))\n", + " probability_signal = math.safe_div(signal_likelihood, (signal_likelihood + noise_likelihood))\n", " action = math.where((0.5 >= probability_signal) | (probability_signal >= 0.68), 2 * (probability_signal - 0.5), 0.) # 1 sigma required to take action\n", " prob_kernel = math.exp(log_kernel * action)\n", " return prob_kernel, probability_signal\n", @@ -310,7 +310,7 @@ "BATCH = batch(batch=128)\n", "STEPS = 50\n", "\n", - "math.seed(0)\n", + "#math.seed(0)\n", "net = u_net(1, 1)\n", "optimizer = adam(net, 0.001)" ] @@ -459,7 +459,7 @@ } ], "source": [ - "math.seed(0)\n", + "#math.seed(0)\n", "net_gd = u_net(1, 1)\n", "optimizer_gd = adam(net_gd, 0.001)\n", "\n", @@ -648,4 +648,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/physicalloss-div.ipynb b/physicalloss-div.ipynb index dc25f4e..ccc85e0 100644 --- a/physicalloss-div.ipynb +++ b/physicalloss-div.ipynb @@ -64,7 +64,7 @@ }, "outputs": [], "source": [ - "!pip install --quiet phiflow==3.3 tqdm\n", + "!pip install --quiet phiflow==3.4 tqdm\n", "from tqdm import tqdm\n", "from phiml import nn\n", "\n",