diff --git a/engibench/problems/airfoil/utils.py b/engibench/problems/airfoil/utils.py index 384f53c7..fc9ccf9f 100644 --- a/engibench/problems/airfoil/utils.py +++ b/engibench/problems/airfoil/utils.py @@ -33,6 +33,7 @@ def _identify_segments(connectivities: npt.NDArray[np.int32]) -> tuple[list[int] prev_id = 0 segment_ids = np.zeros(len(connectivities), dtype=np.float32) seg_id = 0 + j = -1 # Ensure j is always defined for j in range(len(connectivities)): if connectivities[j][0] - 1 != prev_id: diff --git a/engibench/problems/airfoil/v0.py b/engibench/problems/airfoil/v0.py index 1edc334f..0ed18b95 100644 --- a/engibench/problems/airfoil/v0.py +++ b/engibench/problems/airfoil/v0.py @@ -506,15 +506,16 @@ def optimize( # post process -- extract the shape and objective values optisteps_history = [] history = History(self.__local_study_dir + "/output/opt.hst") - iters = list(map(int, history.getCallCounters()[:])) + call_counters = history.getCallCounters() + iters = list(map(int, call_counters)) if call_counters is not None else [] for i in range(len(iters)): vals = history.read(int(iters[i])) if vals is not None and "funcs" in vals and "obj" in vals["funcs"] and not vals["fail"]: - objective = history.getValues(names=["obj"], callCounters=[i], allowSens=False, major=False, scale=True)[ - "obj" - ] - optisteps_history.append(OptiStep(obj_values=np.array(objective), step=vals["iter"])) + values = history.getValues(names=["obj"], callCounters=[i], allowSens=False, major=False, scale=True) + if values is not None and "obj" in values: + objective = values["obj"] + optisteps_history.append(OptiStep(obj_values=np.array(objective), step=vals["iter"])) history.close() diff --git a/engibench/problems/beams2d/backend.py b/engibench/problems/beams2d/backend.py index 108f7012..37f39951 100644 --- a/engibench/problems/beams2d/backend.py +++ b/engibench/problems/beams2d/backend.py @@ -167,7 +167,8 @@ def calc_sensitivity(design: npt.NDArray, st: State, cfg: dict[str, Any] | None """ cfg = cfg or {} sK = ((st.KE.flatten()[np.newaxis]).T * (st.Emin + design ** cfg["penal"] * (st.Emax - st.Emin))).flatten(order="F") - K = coo_matrix((sK, (st.iK, st.jK)), shape=(st.ndof, st.ndof)).tocsc() + K: csc_array = coo_matrix((sK, (st.iK, st.jK)), shape=(st.ndof, st.ndof)).tocsc() + assert K.shape is not None m = K.shape[0] keep = np.delete(np.arange(0, m), st.fixed) K = K[keep, :] @@ -295,6 +296,8 @@ def inner_opt( l1, l2, move = (0.0, 1e9, 0.2) # reshape to perform vector operations xnew = np.zeros(cfg["nelx"] * cfg["nely"]) + xPhys = np.zeros(cfg["nelx"] * cfg["nely"]) + xPrint = np.zeros(cfg["nelx"] * cfg["nely"]) while l1 + l2 > 0 and (l2 - l1) / (l1 + l2) > st.min_ratio: lmid = 0.5 * (l2 + l1) diff --git a/engibench/problems/thermoelastic2d/model/fea_model.py b/engibench/problems/thermoelastic2d/model/fea_model.py index 677719ad..d1aa191d 100644 --- a/engibench/problems/thermoelastic2d/model/fea_model.py +++ b/engibench/problems/thermoelastic2d/model/fea_model.py @@ -185,6 +185,9 @@ def run(self, bcs: dict[str, Any], x_init: np.ndarray | None = None) -> dict[str change_evol = [] obj = [] + f0valm = 0.0 + f0valt = 0.0 + while change > UPDATE_THRESHOLD or iterr < MIN_ITERATIONS: iterr += 1 s_time = time.time() diff --git a/engibench/problems/thermoelastic2d/utils.py b/engibench/problems/thermoelastic2d/utils.py index 3ec2728f..3e33d526 100644 --- a/engibench/problems/thermoelastic2d/utils.py +++ b/engibench/problems/thermoelastic2d/utils.py @@ -90,10 +90,11 @@ def plot_multi_physics( # noqa: PLR0913, PLR0915 y_elements = nely + 1 # Get even and odd Fp elements - if _fp is None: - _fp = np.zeros((x_elements * y_elements * 2,)) - fp_x = _fp[::2] # 8450 / 2 = 4225 = 65 * 65 - fp_y = _fp[1::2] + _fp_array: npt.NDArray[np.float64] = ( + np.zeros((x_elements * y_elements * 2,)) if _fp is None else np.asarray(_fp) + ) # makes sure _fp is a numpy array + fp_x = _fp_array[::2] # 8450 / 2 = 4225 = 65 * 65 + fp_y = _fp_array[1::2] if _um is None: _um = np.zeros((x_elements * y_elements * 2,)) diff --git a/pyproject.toml b/pyproject.toml index de741d50..f04cce0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -233,19 +233,7 @@ enableTypeIgnoreComments = true # This is required as the CI pre-commit does not download the module (i.e. numpy, pygame) # Therefore, we have to ignore missing imports reportMissingImports = "none" -# Some modules are missing type stubs, which is an issue when running pyright locally -reportMissingTypeStubs = false -# For warning and error, will raise an error when -reportInvalidTypeVarUse = "none" -reportOptionalSubscript = "none" - -reportGeneralTypeIssues = "none" # -> commented out raises 489 errors -# reportUntypedFunctionDecorator = "none" # -> pytest.mark.parameterize issues - -# reportOptionalMemberAccess = "none" # -> commented out raises warnings -reportPrivateImportUsage = "warning" # -> - -reportPrivateUsage = "warning" +reportGeneralTypeIssues = "none" # -> commented out raises a lot of errors reportUnboundVariable = "warning" [tool.mypy]