phiflow 3.4 updates

This commit is contained in:
N_T 2025-08-12 09:23:18 +02:00
parent a3de575c19
commit eda7ba974e
6 changed files with 14 additions and 14 deletions

View File

@ -32,7 +32,7 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"!pip install --upgrade --quiet phiflow==3.1\n", "!pip install --upgrade --quiet phiflow==3.4\n",
"from phi.tf.flow import *\n", "from phi.tf.flow import *\n",
"\n", "\n",
"N = 128\n", "N = 128\n",

View File

@ -86,7 +86,7 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"!pip install --upgrade --quiet phiflow==3.1\n", "!pip install --upgrade --quiet phiflow==3.4\n",
"from phi.torch.flow import * \n", "from phi.torch.flow import * \n",
"import pylab # for visualizations later on" "import pylab # for visualizations later on"
] ]
@ -191,7 +191,7 @@
" smoke = advect.mac_cormack(smoke, velocity, dt=1) + INFLOW\n", " smoke = advect.mac_cormack(smoke, velocity, dt=1) + INFLOW\n",
" buoyancy_force = (smoke * (0, 1)).at(velocity)\n", " buoyancy_force = (smoke * (0, 1)).at(velocity)\n",
" velocity = advect.semi_lagrangian(velocity, velocity, dt=1) + buoyancy_force\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", " return smoke, velocity\n",
"\n", "\n",
"for _ in range(20):\n", "for _ in range(20):\n",
@ -214,7 +214,7 @@
"source": [ "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", "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", "\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"
] ]
}, },
{ {

View File

@ -45,12 +45,12 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Using phiflow version: 3.2.0\n" "Using phiflow version: 3.4.0\n"
] ]
} }
], ],
"source": [ "source": [
"!pip install --upgrade --quiet phiflow==3.2\n", "!pip install --upgrade --quiet phiflow==3.4\n",
"from phi.flow import *\n", "from phi.flow import *\n",
"print(\"Using phiflow version: {}\".format(phi.__version__))" "print(\"Using phiflow version: {}\".format(phi.__version__))"
] ]

View File

@ -43,7 +43,7 @@
}, },
"outputs": [], "outputs": [],
"source": [ "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", "#!pip install --upgrade --quiet git+https://github.com/tum-pbs/PhiFlow@develop\n",
"\n", "\n",
"from phi.flow import * # The Dash GUI is not supported on Google colab, ignore the warning\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", " 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 = advect.semi_lagrangian(velocity, velocity, dt) + dt * buoyancy_force\n",
" velocity = diffuse.explicit(velocity, NU, dt)\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", " return velocity, smoke, pressure\n",
"\n", "\n",
"velocity, smoke, pressure = step(velocity, smoke, None, dt=DT)\n", "velocity, smoke, pressure = step(velocity, smoke, None, dt=DT)\n",

View File

@ -254,9 +254,9 @@
" signal_prior = 0.5\n", " signal_prior = 0.5\n",
" expected_amp = 1. * kernel.shape.get_size('x') * inv_kernel # This can be measured\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.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", " 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", " 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", " prob_kernel = math.exp(log_kernel * action)\n",
" return prob_kernel, probability_signal\n", " return prob_kernel, probability_signal\n",
@ -310,7 +310,7 @@
"BATCH = batch(batch=128)\n", "BATCH = batch(batch=128)\n",
"STEPS = 50\n", "STEPS = 50\n",
"\n", "\n",
"math.seed(0)\n", "#math.seed(0)\n",
"net = u_net(1, 1)\n", "net = u_net(1, 1)\n",
"optimizer = adam(net, 0.001)" "optimizer = adam(net, 0.001)"
] ]
@ -459,7 +459,7 @@
} }
], ],
"source": [ "source": [
"math.seed(0)\n", "#math.seed(0)\n",
"net_gd = u_net(1, 1)\n", "net_gd = u_net(1, 1)\n",
"optimizer_gd = adam(net_gd, 0.001)\n", "optimizer_gd = adam(net_gd, 0.001)\n",
"\n", "\n",
@ -648,4 +648,4 @@
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 0
} }

View File

@ -64,7 +64,7 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"!pip install --quiet phiflow==3.3 tqdm\n", "!pip install --quiet phiflow==3.4 tqdm\n",
"from tqdm import tqdm\n", "from tqdm import tqdm\n",
"from phiml import nn\n", "from phiml import nn\n",
"\n", "\n",