@@ -20,33 +20,31 @@ def show_table(log: Dict[str, Any], console: Console) -> None:
20
20
console : Console
21
21
Rich console for output.
22
22
"""
23
- if log :
24
- opt_map = log ["opt_map" ]
25
- optim_status = log ["optim_status" ]
26
- units = log ["units" ]
27
- params = optim_status ["params" ]
23
+ opt_map = log ["opt_map" ]
24
+ optim_status = log ["optim_status" ]
25
+ units = log ["units" ]
26
+ params = optim_status ["params" ]
27
+ if "gradient" not in optim_status :
28
+ grads = [0 ] * len (params )
29
+ else :
28
30
grads = optim_status ["gradient" ]
31
+ table = Table (show_header = True , header_style = "bold magenta" )
32
+ table .add_column ("Parameter" )
33
+ table .add_column ("Value" , justify = "right" )
34
+ table .add_column ("Gradient" , justify = "right" )
35
+ for ii , equiv_ids in enumerate (opt_map ):
36
+ par = params [ii ]
37
+ par = num3str (par )
38
+ par_id = equiv_ids [0 ]
39
+ table .add_row (par_id , par + units [ii ], num3str (grads [ii ]) + units [ii ])
40
+ for par_id in equiv_ids [1 :]:
41
+ table .add_row (par_id , "''" , "''" )
29
42
30
- table = Table (show_header = True , header_style = "bold magenta" )
31
- table .add_column ("Parameter" )
32
- table .add_column ("Value" , justify = "right" )
33
- table .add_column ("Gradient" , justify = "right" )
34
- for ii , equiv_ids in enumerate (opt_map ):
35
- par = params [ii ]
36
- grad = grads [ii ]
37
- par = num3str (par )
38
- grad = num3str (grad )
39
- par_id = equiv_ids [0 ]
40
- table .add_row (par_id , par + units [ii ], grad + units [ii ])
41
- if len (equiv_ids ) > 1 :
42
- for par_id in equiv_ids [1 :]:
43
- table .add_row (par_id , "''" , "''" )
44
-
45
- console .clear ()
46
- print (
47
- f"Optimization reached { optim_status ['goal' ]:0.3g} at { optim_status ['time' ]} \n "
48
- )
49
- console .print (table )
43
+ console .clear ()
44
+ print (
45
+ f"Optimization reached { optim_status ['goal' ]:0.3g} at { optim_status ['time' ]} \n "
46
+ )
47
+ console .print (table )
50
48
51
49
52
50
if __name__ == "__main__" :
0 commit comments