BPN: Bi-level Physics-Informed Neural Networks for PDE Constrained Optimization using Broyden's Hypergradients
Code for paper "BPN: Bi-level Physics-Informed Neural Networks for PDE Constrained Optimization using Broyden's Hypergradients".
pytorch>=1.11.0
scipy>=1.8.1
termcolor>=1.1.0
deepxde>=1.0.0
Running PDECO on 1d Poisson's demo problem,
python poisson_example.py --ft_steps 64 --ift_method broyden --threshold 32 --gpu 0
Running PDECO on Poisson's 2d CG problem,
python poisson_ball_domain.py --ft_steps 256 --ift_method broyden --threshold 32 --gpu 0
Our code relies on deepxde>1.0.0. However, there are some bugs or imcompatible code in current version of DeepXde. Please modify some source code as follows, otherwise you might encounter bugs or unpredictable results.
If you encounter the following errors:
A.
...
File "ENV_PATH/lib/python3.9/site-packages/torch/utils/data/distributed.py", line 99, in __iter__
indices = torch.randperm(len(self.dataset), generator=g).tolist()
RuntimeError: Expected a 'cuda' device type for generator but found 'cpu'
Please modify ENV_PATH/lib/python3.9/site-packages/torch/utils/data/distributed.py
(line 97):
# deterministically shuffle based on epoch and seed
g = torch.Generator()
g.manual_seed(self.seed + self.epoch)
indices = torch.randperm(len(self.dataset), generator=g).tolist()
to:
# deterministically shuffle based on epoch and seed
g = torch.Generator(device="cuda") # add this
g.manual_seed(self.seed + self.epoch)
indices = torch.randperm(len(self.dataset), generator=g).tolist()
B.
...
File "ENV_PATH/lib/python3.9/site-packages/deepxde/model.py", line 225, in outputs_losses
outputs_ = self.net(self.net.inputs)
...
File "ENV_PATH/lib/python3.9/site-packages/torch/nn/functional.py", line 1848, in linear
return torch._C._nn.linear(input, weight, bias)
RuntimeError: expected scalar type Float but found Double
Please modify ENV_PATH/lib/python3.9/site-packages/deepxde/model.py
(line 225):
self.net.train(mode=training)
self.net.inputs = torch.as_tensor(inputs)
self.net.inputs.requires_grad_()
outputs_ = self.net(self.net.inputs)
to:
self.net.train(mode=training)
self.net.inputs = torch.as_tensor(inputs)
self.net.inputs.requires_grad_()
outputs_ = self.net(self.net.inputs.float()) # add this
C.
Modify deepxde.data.test_points(boundary=True)
D.
Add capturable=True
to deepxde/optimizers/pytorch/optimizers
.
If you use Bi-level PINN (BPN) your research, please use the following BibTeX entry.
@article{hao2022bi,
title={Bi-level physics-informed neural networks for pde constrained optimization using broyden's hypergradients},
author={Hao, Zhongkai and Ying, Chengyang and Su, Hang and Zhu, Jun and Song, Jian and Cheng, Ze},
journal={arXiv preprint arXiv:2209.07075},
year={2022}
}