Fixed save/load for bundle solver
@@ -11,6 +11,7 @@ from itertools import chain
import inspect
import ast
import types
+import random
# Is Dev mode
try:
@@ -202,6 +203,25 @@ def get_sample_solution2D(solver):
pass
return sample_solution_curve
+def get_sample_solutionBundle1D(solver):
+ sample_solution_curve = []
+ try:
+ t = np.linspace(solver.r_min[0], solver.r_max[0], 10 *
+ (int(solver.r_max[0]-solver.r_min[0])))
+
+ values = [(random.random()*(solver.r_max[i]-solver.r_min[i]) + solver.r_min[i])*np.ones(len(t)) for i in range(1, len(solver.r_min))]
+ sample_solution = solver.get_solution()(t, *values)
+
+ if not isinstance(sample_solution, list):
+ sample_solution = [sample_solution]
+
+ for i in range(len(sample_solution)):
+ sample_solution[i] = sample_solution[i].cpu().detach().numpy().tolist()
+
+ sample_solution_curve = [t.tolist(), sample_solution]
+ except:
+ pass
+ return sample_solution_curve
def get_networks(solver):
networks = []
@@ -280,6 +300,10 @@ class PretrainedSolver():
sample_solution = get_sample_solution1D(self)
elif self.__class__.__name__ == "Solver2D":
sample_solution = get_sample_solution2D(self)
+ elif self.__class__.__name__ == "BundleSolver1D":
+ sample_solution = get_sample_solutionBundle1D(self)
+ else:
+ sample_solution = None #Temp Fix to avoid error, until conditions made for all solvers
diff_equation_details = {
"equation": get_source(self.diff_eqs),
@@ -491,6 +515,21 @@ class PretrainedSolver():
optimizer=optimizer,
loss_fn=load_dict['loss_fn'],
metrics=load_dict['metrics'])
+ elif load_dict["type_name"] == "BundleSolver1D":
+ t_min = load_dict['solver'].r_min[0]
+ t_max = load_dict['solver'].r_max[0]
+
+ solver = cls(ode_system=de_system,
+ conditions=cond,
+ metrics=load_dict['metrics'],
+ nets=nets,
+ optimizer=optimizer,
+ train_generator=train_generator,
+ valid_generator=valid_generator,
+ t_min=t_min,
+ t_max=t_max,
+ theta_min=tuple(load_dict['solver'].r_min[1:]),
+ theta_max=tuple(load_dict['solver'].r_max[1:]))
if best_nets != None:
solver.best_nets = best_nets
