Skip to content

Commit

Permalink
Make logger info more meaningful
Browse files Browse the repository at this point in the history
  • Loading branch information
mbkumar committed Nov 3, 2023
1 parent 4da5214 commit 553eda1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
18 changes: 14 additions & 4 deletions src/simsopt/objectives/least_squares.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ class LeastSquaresProblem(Optimizable):
goals: Targets for residuals in optimization
weights: Weight associated with each of the residual
funcs_in: Input functions (Generally one of the output functions of
the Optimizable instances
the Optimizable instances
depends_on: (Alternative initialization) Instead of specifying funcs_in,
one could specify the Optimizable objects
one could specify the Optimizable objects
opt_return_fns: (Alternative initialization) If using *depends_on*,
specify the return functions associated with each Optimizable
object
specify the return functions associated with each Optimizable object
"""

def __init__(self,
Expand Down Expand Up @@ -81,6 +80,7 @@ def __init__(self,

super().__init__(depends_on=depends_on, opt_return_fns=opt_return_fns,
funcs_in=funcs_in)
self._func_names = self._get_func_names()

@classmethod
def from_sigma(cls,
Expand Down Expand Up @@ -135,6 +135,16 @@ def from_tuples(cls,
funcs_in, goals, weights = zip(*tuples)
return cls(goals, weights, funcs_in=funcs_in, fail=fail)

def _get_func_names(self):
func_names = []
for fn in self.funcs_in:
func_names.append(fn.__qualname__)
return func_names

@property
def residual_names(self):
return self._func_names

def unweighted_residuals(self, x=None, *args, **kwargs):
"""
Return the unweighted residuals (f_in - goal)
Expand Down
23 changes: 10 additions & 13 deletions src/simsopt/solve/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,18 @@ def objective(x):
# Initialize log file
datalogging_started = True
ndofs = prob.dof_size
objective_file.write(
f"Problem type:\nleast_squares\nnparams:\n{ndofs}\n")
objective_file.write("function_evaluation,seconds")
x_names = prob.dof_names
fn_names = prob.residual_names
head_str = f"Problem type: Least Squares\nnparams: {ndofs}\n"
head_str += "function_evaluation,seconds"
for j in range(ndofs):
objective_file.write(f",x({j})")
objective_file.write(",objective_function\n")
head_str += f",{x_names[j]}"
head_str += ",objective_function"
objective_file.write(head_str + "\n")

residuals_file.write(
f"Problem type:\nleast_squares\nnparams:\n{ndofs}\n")
residuals_file.write("function_evaluation,seconds")
for j in range(ndofs):
residuals_file.write(f",x({j})")
residuals_file.write(",objective_function")
for j in range(len(residuals)):
residuals_file.write(f",F({j})")
residuals_file.write(head_str)
for name in fn_names:
residuals_file.write(f",{name}")
residuals_file.write("\n")

elapsed_t = time() - start_time
Expand Down

0 comments on commit 553eda1

Please sign in to comment.