Comments (3)
Hi Nikolai,
Thanks for your feedback!
Unfortunately we don't have anyone with a lot of experience in PyTorch in our group, so we don't yet have advanced tests.
I'll look into the error shortly and post a fix.
Best,
Philipp
from phiflow.
I have fixed this issue in the develop branch. The following script now runs until the last line.
from phi.torch.flow import *
from torch.utils.data import TensorDataset, DataLoader
inputs = torch.rand(1000, 10, 10, 1)
targets = torch.rand(1000, 10, 10, 1)
dataset = TensorDataset(inputs, targets)
dataloader = DataLoader(dataset, batch_size=10)
domain = Domain([10, 10], boundaries=PERIODIC)
sz = domain.staggered_grid(0).staggered_tensor().shape
initial_velocity = torch.zeros(*sz)
initial_velocity = initial_velocity.expand(10, *initial_velocity.shape[1:])
velocity = torch.nn.Parameter(initial_velocity)
optimizer = torch.optim.Adam([velocity], lr=1e-3)
for epoch in range(10):
for batch_index, (inputs, targets) in enumerate(dataloader):
optimizer.zero_grad()
domain = Domain([10, 10], boundaries=PERIODIC)
fluid = Fluid(domain, batch_size=10, density=inputs, velocity=velocity)
density = advect.semi_lagrangian(fluid.density, fluid.velocity, dt=1)
density = diffuse(density, 1 * 0.1, substeps=1)
loss = math.l2_loss(density.data - targets)
loss.backward()
optimizer.step()
The optimizer.step()
still complains that
more than one element of the written-to tensor refers to a single memory location. Please clone() the tensor before performing the operation.
It sounds to me like the problem lies in the setup. Can you confirm this?
Note that Fluid.density
is read-only. Use fluid.copied_with(density=new_density)
to make an altered copy.
from phiflow.
Thank you for such a prompt response. Indeed, Fluid
object is created correctly now. I also confirm that the problem with optimizer lies in the setup, to be precise, in the line initial_velocity = initial_velocity.expand(10, *initial_velocity.shape[1:])
. This operation should be done at each step when creating Fluid
object. I am now closing the issue, thank you again!
from phiflow.
Related Issues (20)
- jit_compile does not work with ZERO_GRADIENT extrapolation HOT 1
- jit_compile pytorch does not work with values requiring gradients HOT 3
- Free stream boundary condition HOT 2
- installation error in python 3.11 HOT 4
- Override boundary condition on small patch of an edge HOT 8
- Error when I want to run demo HOT 9
- Code of Writing Fluid Simulations in ΦFlow doesn't work HOT 5
- what differential equation does the velocity satisfy HOT 4
- Adding forcing term in fluid simulation and verifying the simulation results via residual of the pde HOT 5
- Custom geometry HOT 1
- Simulate two phase flow (immiscible) HOT 5
- About deprecation of instance checks HOT 3
- Question regarding tensor transpose HOT 4
- How to Insert center values into staggerGrid class? HOT 5
- Applying free stream boundary condition HOT 3
- Extrapolations get added when adding fields HOT 5
- jit compile extrapolation HOT 2
- values returned from jit compiled function HOT 1
- Can I use this great libarary to read .uni file? HOT 1
- Flat obstacles in 3D space HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phiflow.