optimization-and-learning
Routes PhiFlow gradient, Jacobian, solve, and inverse-design workflows.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- optimization-and-learning
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Routes PhiFlow gradient, Jacobian, solve, and inverse-design workflows.
- disable-model-invocation
- true
02 资源文件 3
- 参考文档references/troubleshooting.md2.4 KB
- 参考文档references/workflows.md2.6 KB
- 脚本scripts/throw_gradient_descent.py2.3 KB
03 SKILL.md 正文
Optimization and Learning
Use this sub-skill when a PhiFlow task depends on gradients, Jacobians, backpropagation through simulation, linear or nonlinear solves, or other optimization loops built on top of the field and physics APIs.
Route here for
math.functional_gradient(),math.gradient(), andmath.jacobian()math.jit_compile()andmath.jit_compile_linear()math.solve_linear(),math.solve_nonlinear(), andmath.minimize()field.functional_gradient(),field.l2_loss(),field.l1_loss(), andfield.frequency_loss()- inverse problems such as the throw optimization example
- differentiable fluid / PDE loops that are optimized end-to-end
- linearized mesh or FVM workflows that use
math.matrix_from_function()
Do not route here
- plain simulation without optimization ->
physics-and-simulation - installation or backend setup ->
installation-and-backends - field / geometry / scene plumbing ->
core-data-and-geometry - plotting, display, or scalar log rendering ->
visualization-and-ui
Start with these imports
from phi.flow import *
from phi import field, math
from phi.physics import advect, diffuse, fluid
from phiml.math import Solve, precision
from phiml.backend import Backend
Most common decisions
- Choose the gradient API: use
math.functional_gradient()for the most common differentiable-simulation loops andmath.jacobian()when you need a Jacobian for a backend that supports it. - Pick a loss intentionally:
field.l2_loss()is the usual smoke-test loss;field.frequency_loss()is useful when the task is about regularizing spatial detail. - Reuse solve guesses: pass
Solve(x0=previous_solution)in iterative loops so the pressure or state guess carries across steps. - Respect backend limitations: JAX requires pure functions inside
jit_compile(). PyTorch and custom-gradient workflows have their own tracing constraints. - Use precision carefully:
math.precision(64)is useful for gradient smoke checks and backend comparisons.
Verified signatures to rely on
math.functional_gradient(f, wrt=None, get_output=True) -> Callablemath.gradient(f, wrt=None, get_output=True) -> Callablemath.jacobian(f, wrt=None, get_output=True) -> Callablemath.jit_compile(f=None, auxiliary_args='', forget_traces=None)math.jit_compile_linear(f=None, auxiliary_args=None, forget_traces=None)math.solve_linear(f, y, solve, *f_args, grad_for_f=False, f_kwargs=None, **f_kwargs_)math.solve_nonlinear(f, y, solve)math.minimize(f, solve)field.functional_gradient(f, wrt=None, get_output=True)
Bundled references and helper
- Detailed workflows:
references/workflows.md - Failure handling:
references/troubleshooting.md - Throw gradient smoke:
scripts/throw_gradient_descent.py
From this sub-skill directory, run the smoke helper when you need to verify the core gradient path:
python scripts/throw_gradient_descent.py --iterations 10 --step-size 0.2
The helper exercises a tiny differentiable throw optimization loop across the installed backends that support Jacobians.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).