From 2eb856d57ea3050a3d26b4967046f611f4678d30 Mon Sep 17 00:00:00 2001 From: Jasper Bussemaker Date: Wed, 22 Nov 2023 13:01:10 +0100 Subject: [PATCH 1/2] Expose dv conditionality for assignment problems --- sb_arch_opt/problems/assignment.py | 13 ++++++++++--- sb_arch_opt/tests/problems/test_assignment.py | 10 +++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/sb_arch_opt/problems/assignment.py b/sb_arch_opt/problems/assignment.py index 831d544..c983ea4 100644 --- a/sb_arch_opt/problems/assignment.py +++ b/sb_arch_opt/problems/assignment.py @@ -75,9 +75,16 @@ def _get_n_valid_discrete(self) -> int: def _is_conditionally_active(self) -> List[bool]: _, is_act_all = self.all_discrete_x - if is_act_all is None: - raise RuntimeError(f'_is_conditionally_active not implemented for {self.__class__.__name__}') - return list(np.any(~is_act_all, axis=0)) + if is_act_all is not None: + return list(np.any(~is_act_all, axis=0)) + + if isinstance(self._problem, MultiAssignmentProblem): + dv_cond = [] + for assignment_manager in self._problem.assignment_managers: + dv_cond += [dv.conditionally_active for dv in assignment_manager.design_vars] + return dv_cond + + return [dv.conditionally_active for dv in self._problem.assignment_manager.design_vars] def _gen_all_discrete_x(self) -> Optional[Tuple[np.ndarray, np.ndarray]]: if isinstance(self._problem, AnalyticalProblemBase): diff --git a/sb_arch_opt/tests/problems/test_assignment.py b/sb_arch_opt/tests/problems/test_assignment.py index 3cc547c..0e083d9 100644 --- a/sb_arch_opt/tests/problems/test_assignment.py +++ b/sb_arch_opt/tests/problems/test_assignment.py @@ -29,6 +29,8 @@ def test_partitioning(): Partitioning().print_stats() run_test_hierarchy(PartitioningCovering(), 1.71) + _ = PartitioningCovering().is_conditionally_active + @check_dependency() def test_unordered(): @@ -36,6 +38,8 @@ def test_unordered(): UnordNonReplCombLarge().print_stats() UnorderedComb().print_stats() + _ = UnorderedComb().is_conditionally_active + @check_dependency() def test_assign_enc_gnc(): @@ -49,8 +53,4 @@ def test_assign_enc_gnc(): assert problem.get_n_valid_discrete() == n_valid x_all, _ = problem.all_discrete_x - if x_all is not None: - _ = problem.is_conditionally_active - else: - with pytest.raises(RuntimeError): - _ = problem.is_conditionally_active + _ = problem.is_conditionally_active From a08248cab64cb5f438c2ac2f0c5b3eb1d1aefa11 Mon Sep 17 00:00:00 2001 From: Jasper Bussemaker Date: Wed, 22 Nov 2023 13:01:37 +0100 Subject: [PATCH 2/2] Also run basic tests on dev --- .github/workflows/tests_basic.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests_basic.yml b/.github/workflows/tests_basic.yml index 6260063..5b28e6f 100644 --- a/.github/workflows/tests_basic.yml +++ b/.github/workflows/tests_basic.yml @@ -5,9 +5,9 @@ name: Basic Tests on: push: - branches: [ "main" ] + branches: [ "main", "dev" ] pull_request: - branches: [ "main" ] + branches: [ "main", "dev" ] jobs: test: