diff --git a/afc/ctrlWrapper.py b/afc/ctrlWrapper.py index 6049ada..d652526 100644 --- a/afc/ctrlWrapper.py +++ b/afc/ctrlWrapper.py @@ -329,12 +329,13 @@ def compute(self): # with open('cfg_{}.json'.format(data.index[0]), 'w') as f: # f.write(json.dumps(cfg)) - print_error = self.input['parameter']['wrapper']['printing'] + printing = self.input['parameter']['wrapper']['printing'] self.res = \ - self.controller.do_optimization(self.data, parameter=self.input['parameter'], + self.controller.do_optimization(self.data, + parameter=self.input['parameter'], options=self.input['parameter']['solver_options'], - tee=self.input['parameter']['wrapper']['printing'], - print_error=print_error) + tee=printing, + print_error=printing) duration, objective, df, model, result, termination, parameter = self.res self.output['optall_duration'] = time.time() - st1 @@ -342,7 +343,7 @@ def compute(self): st1 = time.time() self.output['opt_duration'] = float(duration) self.output['opt_termination'] = str(termination) - self.output['opt_objective'] = float(objective) if objective else np.nan + self.output['opt_objective'] = float(objective) if objective else None self.output['glaremode'] = list(gmodes) if objective: uShade = df[[f'Facade State {z}' for \ @@ -366,9 +367,11 @@ def compute(self): except Exception as e: self.msg += f'\nERROR: {e}\n\n{traceback.format_exc()}' + for k in self.output: + self.output[k] = None return self.msg -def make_inputs(parameter, df): +def make_inputs(parameter, df, ext_df=pd.DataFrame()): """Utility function to make inputs.""" df = df.copy(deep=True) @@ -398,6 +401,10 @@ def make_inputs(parameter, df): df.loc[:, 'temp_wall_max'] = 1e3 df.loc[:, 'temp_wall_min'] = 0 + # Add External inputs (if any) + for c in ext_df: + df[c] = ext_df[c] + # Map parameter and make Inputs object inputs = {} inputs['radiance'] = parameter['radiance'] diff --git a/dev/Development-ControllerWrapper.ipynb b/dev/Development-ControllerWrapper.ipynb index c9f8a38..d3029e4 100644 --- a/dev/Development-ControllerWrapper.ipynb +++ b/dev/Development-ControllerWrapper.ipynb @@ -34,8 +34,7 @@ "source": [ "# configure mpl\n", "import matplotlib as mpl\n", - "mpl.rcParams['figure.dpi'] = 72\n", - "%matplotlib inline" + "mpl.rcParams['figure.dpi'] = 72" ] }, { @@ -62,15 +61,15 @@ "All Input variables: dict_keys(['paths', 'radiance', 'df_input', 'wf_all', 'facade_initial', 'temps_initial', 'parameter'])\n", "WARNING: view_angle: Window below viewpoint.\n", "Log-message:\n", - " Duration [s]\t\t0.19\n", + " Duration [s]\t\t0.29\n", "Objective [$]\t\t20.29\t\t\t7.58 (Total Cost)\n", "Cost [$]\t\t13.32 (Energy)\t6.98 (Demand)\n", "CO2 Emissions [kg]\t\t0.0\n", "\n", "Duration:\n", - " {'rad_duration': 7.62345027923584, 'varts_duration': 0.12901592254638672, 'optall_duration': 0.2766547203063965, 'glare_duration': 69.99816942214966, 'opt_duration': 0.19001984596252441, 'outputs_duration': 0.006535053253173828, 'duration': 78.04731726646423}\n", + " {'rad_duration': 17.785902976989746, 'varts_duration': 0.18678975105285645, 'optall_duration': 0.43532633781433105, 'glare_duration': 96.1897702217102, 'opt_duration': 0.2924964427947998, 'outputs_duration': 0.009624481201171875, 'duration': 114.62892770767212}\n", "Optimization:\n", - " {'opt_objective': 20.29202698, 'opt_duration': 0.19001984596252441, 'opt_termination': 'optimal', 'duration': 78.04731726646423}\n" + " {'opt_objective': 20.29202698, 'opt_duration': 0.2924964427947998, 'opt_termination': 'optimal', 'duration': 114.62892770767212}\n" ] }, { @@ -416,12 +415,13 @@ " # with open('cfg_{}.json'.format(data.index[0]), 'w') as f:\n", " # f.write(json.dumps(cfg))\n", "\n", - " print_error = self.input['parameter']['wrapper']['printing']\n", + " printing = self.input['parameter']['wrapper']['printing']\n", " self.res = \\\n", - " self.controller.do_optimization(self.data, parameter=self.input['parameter'],\n", + " self.controller.do_optimization(self.data,\n", + " parameter=self.input['parameter'],\n", " options=self.input['parameter']['solver_options'],\n", - " tee=self.input['parameter']['wrapper']['printing'],\n", - " print_error=print_error)\n", + " tee=printing,\n", + " print_error=printing)\n", " duration, objective, df, model, result, termination, parameter = self.res\n", " self.output['optall_duration'] = time.time() - st1\n", "\n", @@ -429,7 +429,7 @@ " st1 = time.time()\n", " self.output['opt_duration'] = float(duration)\n", " self.output['opt_termination'] = str(termination)\n", - " self.output['opt_objective'] = float(objective) if objective else np.nan\n", + " self.output['opt_objective'] = float(objective) if objective else None\n", " self.output['glaremode'] = list(gmodes)\n", " if objective:\n", " uShade = df[[f'Facade State {z}' for \\\n", @@ -453,9 +453,11 @@ "\n", " except Exception as e:\n", " self.msg += f'\\nERROR: {e}\\n\\n{traceback.format_exc()}'\n", + " for k in self.output:\n", + " self.output[k] = None\n", " return self.msg\n", "\n", - "def make_inputs(parameter, df):\n", + "def make_inputs(parameter, df, ext_df=pd.DataFrame()):\n", " \"\"\"Utility function to make inputs.\"\"\"\n", "\n", " df = df.copy(deep=True)\n", @@ -485,6 +487,10 @@ " df.loc[:, 'temp_wall_max'] = 1e3\n", " df.loc[:, 'temp_wall_min'] = 0\n", "\n", + " # Add External inputs (if any)\n", + " for c in ext_df:\n", + " df[c] = ext_df[c]\n", + "\n", " # Map parameter and make Inputs object\n", " inputs = {}\n", " inputs['radiance'] = parameter['radiance']\n",