Compare commits

...

3 Commits

Author SHA1 Message Date
N_T
45d2b6529e more phiflow 3.4 updates for HEAT SIP 2025-08-12 10:58:56 +02:00
N_T
1396482270 more phiflow 3.4 updates; warning SoL code not yet working 2025-08-12 09:26:34 +02:00
N_T
eda7ba974e phiflow 3.4 updates 2025-08-12 09:23:18 +02:00
7 changed files with 19 additions and 19 deletions

View File

@ -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",

View File

@ -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"
]
},
{

View File

@ -134,7 +134,7 @@
"source": [
"try:\n",
" import google.colab # to ensure that we are inside colab\n",
" !pip install --upgrade --quiet phiflow==3.3\n",
" !pip install --upgrade --quiet phiflow==3.4\n",
" #!pip install --upgrade --quiet git+https://github.com/tum-pbs/PhiFlow@develop\n",
" \n",
" # for pbdl-dataset:\n",
@ -172,7 +172,7 @@
"random.seed(42)\n",
"np.random.seed(42)\n",
"\n",
"math.seed(42) # phiflow seed\n",
"#math.seed(42) # phiflow seed (note, this can cause an error on some backends; activate if possible)\n",
"math.set_global_precision(32) # single precision\n",
"\n",
"USE_CPU = 0\n",
@ -255,7 +255,7 @@
"\n",
" # mass conservation (pressure solve)\n",
" pressure = None\n",
" velocity, pressure = fluid.make_incompressible(velocity, self.obstacles)\n",
" velocity, pressure = fluid.make_incompressible(velocity, self.obstacles, Solve('CG', 1e-3))\n",
" self.solve_info = { 'pressure': pressure, 'advected_velocity': advected_velocity }\n",
"\n",
" return [marker, velocity]\n",

View File

@ -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__))"
]

View File

@ -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",

View File

@ -84,7 +84,7 @@
}
],
"source": [
"!pip install --upgrade --quiet phiflow==3.1\n",
"!pip install --upgrade --quiet phiflow==3.4\n",
"from phi.torch.flow import * # switch to TF with \"phi.tf.flow\""
]
},
@ -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)"
]
@ -347,7 +347,7 @@
"def loss_function(net, x_gt: CenteredGrid, sip: bool):\n",
" y_target = diffuse.fourier(x_gt, 8., 1)\n",
" with math.precision(32):\n",
" prediction = field.native_call(net, field.to_float(y_target)).vector[0]\n",
" prediction = field.native_call(net, field.to_float(y_target))\n",
" prediction += field.mean(x_gt) - field.mean(prediction)\n",
" x = field.stop_gradient(prediction)\n",
" if sip:\n",
@ -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
}
}

View File

@ -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",