@@ -20,38 +20,31 @@ def show_table(log: Dict[str, Any], console: Console) -> None:
2020 console : Console
2121 Rich console for output.
2222 """
23- if log :
24- opt_map = log ["opt_map" ]
25- optim_status = log ["optim_status" ]
26- units = log ["units" ]
27- params = optim_status ["params" ]
28- grads = optim_status .pop ("gradient" , None )
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 :
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 , "''" , "''" )
2942
30- table = Table (show_header = True , header_style = "bold magenta" )
31- table .add_column ("Parameter" )
32- table .add_column ("Value" , justify = "right" )
33- if grads is not None :
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- if grads is not None :
40- table .add_row (par_id , par + units [ii ], num3str (grads [ii ]) + units [ii ])
41- if len (equiv_ids ) > 1 :
42- for par_id in equiv_ids [1 :]:
43- table .add_row (par_id , "''" , "''" )
44- else :
45- table .add_row (par_id , par + units [ii ])
46- if len (equiv_ids ) > 1 :
47- for par_id in equiv_ids [1 :]:
48- table .add_row (par_id , "''" )
49-
50- console .clear ()
51- print (
52- f"Optimization reached { optim_status ['goal' ]:0.3g} at { optim_status ['time' ]} \n "
53- )
54- 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 )
5548
5649
5750if __name__ == "__main__" :
0 commit comments