<jupyter_start><jupyter_text>1 check mesh shape of cars latents<jupyter_code>def load_pressure_predictor(load_directory):
    model = SplineCNN8Residuals(3)
    model.load_state_dict(torch.load(load_directory + "/cfdModel.nn"))
    model = model.to("cuda:0").eval()
    return model

def load_latent_vectors(load_directory, checkpoint):
    filename = os.path.join(
        load_directory, checkpoint + ".pth"
    )
    if not os.path.isfile(filename):
        raise Exception(
            "The experiment directory ({}) does not include a latent code file"
            + " for checkpoint '{}'".format(load_directory, checkpoint)
        )
    data = torch.load(filename)
    return data["latent_codes"].cuda()

def load_decoder(load_directory, checkpoint):
    specs_filename = os.path.join(load_directory, "specs.json")
    if not os.path.isfile(specs_filename):
        raise Exception(
            'The experiment directory does not include specifications file "specs.json"'
        )
    specs = json.load(open(specs_filename))
    latent_size = specs["CodeLength"]
    decoder = Decoder(latent_size, **specs["NetworkSpecs"])
    decoder = torch.nn.DataParallel(decoder)
    saved_model_state = torch.load(os.path.join(load_directory, checkpoint +".pth"))
    decoder.load_state_dict(saved_model_state["model_state_dict"])
    decoder = decoder.module.cuda()
    decoder.eval()
    return decoder
DIR_to_load_data = 'starting_data'
experiment_directory = "data_for_this_experiments"

predictor = load_pressure_predictor(DIR_to_load_data)

decoder = load_decoder(DIR_to_load_data, "decoderModel")

latent_vectors = load_latent_vectors(DIR_to_load_data, "latentCodes").detach()

AvgTransform = np.load(DIR_to_load_data + "/avg_trans_matrix.npy") #computeAvgTransform()

LATENT_TO_OPTIMIZE = latent_vectors[32]
LATENT_KD_TREE = KDTree(np.array([lv.cpu().detach().numpy()[0] for lv in latent_vectors]))
torch.manual_seed(0)

# 1 prepare data
latent = latent_vectors[32]

# 2 prepare model
#decoder = load_decoder(DIR_to_load_data, "decoderModel")
#predictor = load_pressure_predictor(DIR_to_load_data)

# init and setup one experiment
exp = single_experiment()
# One experiment: setup objective function
objective = cfd_obj(decoder, predictor, latent_vectors, AvgTransform, LATENT_KD_TREE)
exp.set_objective(objective)
opt = adam(dim=256)
optParas = {
         'x0': latent,
         'alpha': 8e-3,
         'beta_1': 0.9, 
         'beta_2': 0.999, 
         'epsilon': 1e-11, 
         'max_iter': 10,
         'tol': 1e-6,              
         'verbose': True,
         'record': True}
opt.set_parameters(optParas)
exp.set_optimizer(opt)
%time stats_ada = exp.do()<jupyter_output>*******starting optimisation from intitial point:  0.57972956
first part of loss:  -0.008534351
second part of loss:  0.0
third part of loss:  0.0
Drag_point:  0.32287428
Drag*normal:  0.19913064 backward loss:  0.00021854066
penalty:  0.079743706
loss + penalty:  0.079962246
norm of grad 0.39857736 

first part of loss:  -0.015950955
second part of loss:  0.0
third part of loss:  0.0
Drag_point:  0.33058915
Drag*normal:  0.20049322 backward loss:  -0.00024022127
penalty:  0.073850594
loss + penalty:  0.07361037
norm of grad 0.36500147 

first part of loss:  -0.020603903
second part of loss:  0.0
third part of loss:  0.0
Drag_point:  0.32830766
Drag*normal:  0.19876316 backward loss:  -4.1640382e-05
penalty:  0.07053756
loss + penalty:  0.07049592
norm of grad 0.34678316 

first part of loss:  -0.020075232
second part of loss:  0.0
third part of loss:  0.0
Drag_point:  0.325788
Drag*normal:  0.19493012 backward loss:  -0.00014247079
penalty:  0.068881445
loss + penalty:  0.068738975
[...]
{'fraction_non_alphanumeric': 0.11141230685822716, 'fraction_numerical': 0.08620222282461372, 'mean_word_length': 3.993234100135318, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '573470', 'license': 'MIT', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1313, 'n_words': 294, 'path': 'ExpsOnCFD.ipynb', 'repo_name': 'huajian1069/non-convex_optimisation', 'size': '3689'}