numagic / lumos

scalable accelerated optimal control
MIT License
16 stars 0 forks source link

logging bug: decision variable scaling and cyclic constraints #78

Closed yunlongxu-numagic closed 1 year ago

yunlongxu-numagic commented 1 year ago

as such, the evaluated function outputs are also done with the wrong inputs (scaled inputs)

see here

yunlongxu-numagic commented 1 year ago

it's a little complicated, see here

yunlongxu-numagic commented 1 year ago

an additional issue: when the larger infeasibility is cyclic cons, the debugger gives wrong name and location of the maximum infeasibility (it gives the constraint that has the larger violation among the group excluding cyclic cons)

this is because cyclic cons are not recorded, to record, we can add the following snippet to the logging here:

        # HACK: try to include cyclic cons in logging
        # Cyclic-con is NOT defined at every point on the mesh, but to log, we need to
        # make it also num_stages x num_columns. So make only the last stages non-zero
        cyclic_cons = np.zeros((self.num_stages, len(self._cyclic_vars)))
        cyclic_cons[-1, :] = cons["cyclic"]
        cyclic_con_columns = ["cyclic_con." + n for n in self._cyclic_vars]
        cylic_cons_df = pd.DataFrame(data=cyclic_cons, columns=cyclic_con_columns)

        dec_var_df = pd.DataFrame(
            data=self.dec_var_operator.get_stage_var_array(unscaled_dec_var),
            columns=self.dec_var_operator.stage_var_names,
        )

        outputs_df = pd.DataFrame(
            model_return.outputs,
            columns=["outputs." + n for n in self.model.get_group_names("outputs")],
        )

        df_list = [
            dec_var_df,
            outputs_df,
            interval_cons_df,
            stage_cons_df,
            cylic_cons_df,
        ]
yunlongxu-numagic commented 1 year ago

closed by #79