Repository navigation
Expand file tree
/
Copy pathmain_TO.py
More file actions
75 lines (61 loc) · 2.52 KB
/
Copy pathmain_TO.py
File metadata and controls
75 lines (61 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import argparse
import torch
import random
import time
from datetime import datetime
from onescience.models.GPs import GPPLUS
from onescience.utils.GP_TO import set_seed,get_data_fluid
from train import find_TO
def main(args):
tkwargs = {
"dtype": torch.float,
"device": torch.device(f"cuda:{args.gpu}" if torch.cuda.is_available() else "cpu"),
}
# Fix Seed
random_states = 11
problem = args.problem # 从参数获取problem
############################### Generate Data ##############################################
set_seed(random_states)
NOW = datetime.now()
d = NOW.strftime("%B%d_%H-%M")
N_train_per_BC = 25
N_col_domain = 10000
X_col, X_train, Sol_train = get_data_fluid(problem=problem, N_col_domain=N_col_domain,
N_train=N_train_per_BC)
mean_function = 'neural_network'
NN_archi =[64,64,64,64,64]
# Names of the outputs
output_names = ['u', 'v', 'p', 'ro']
# Define all models as a list of models
models = [
GPPLUS(
train_x=X_train[i].type(tkwargs["dtype"]),
train_y=Sol_train[i].type(tkwargs["dtype"]),
collocation_x=X_col.type(tkwargs["dtype"]).clone().requires_grad_(True).to(tkwargs["device"]),
basis=mean_function,
NN_layers_base=NN_archi,
name_output=name,
device=tkwargs["device"],
dtype=tkwargs["dtype"]
).to(**tkwargs)
for i, name in enumerate(output_names)
]
############################### Fit Model ##########################################
start_time = time.time() # get the current time
loss_history = find_TO(model_list=models,
num_iter=50000,
lr_default=0.001,
title=f"seed{random_states}_{problem}_{d}",
problem=problem,
diff_method='Numerical')
end_time = time.time()
print(f'The total time in seconds is {end_time - start_time}')
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run TO model training")
parser.add_argument('--problem', type=str, default='doublepipe',
choices=['doublepipe', 'diffuser', 'rugby', 'pipebend'],
help="Problem name to select the dataset and configuration")
parser.add_argument('--gpu', type=int, default=0,
help="GPU id to use, default=0")
args = parser.parse_args()
main(args)