Skip to content

Commit

Permalink
Merge pull request #71 from swryan/poem_integ
Browse files Browse the repository at this point in the history
Simulate PR 3214
  • Loading branch information
swryan authored Jun 10, 2024
2 parents 91f809e + 163051e commit 332aed3
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 3.32.1-dev
current_version = 3.33.1-dev
commit = False
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ body:
attributes:
label: OpenMDAO Version
description: What version of OpenMDAO is being used.
placeholder: "3.32.1-dev"
placeholder: "3.33.1-dev"
validations:
required: true
- type: textarea
Expand Down
23 changes: 17 additions & 6 deletions .github/scripts/get_poem_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ def get_poem_id(repository, pull_id):
print(f"Checking Pull Request #{pull_id} for associated issue...")
print("-------------------------------------------------------------------------------")
try:
pull_json = subprocess.check_output(["gh", "--repo", repository,
"issue", "view", "--json", "body", pull_id])
p = subprocess.run(["gh", "--repo", repository, "issue", "view", "--json", "body", pull_id],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except subprocess.CalledProcessError as err:
print(f"Unable to access pull request #{pull_id}:\nrc={err.returncode}")
print(f"stdout:\n------\n{p.stdout}")
print(f"stderr:\n------\n{p.stderr}")
return ERROR

pull_body = json.loads(pull_json)["body"]
print(f"stdout:\n------\n{p.stdout}")
print(f"stderr:\n------\n{p.stderr}")

pull_body = json.loads(p.stdout)["body"]

issue_id = ""

Expand All @@ -58,14 +63,20 @@ def get_poem_id(repository, pull_id):
print(f"Checking Issue #{issue_id} for associated POEM...")
print("-------------------------------------------------------------------------------")

repository = repository.replace('swryan', 'OpenMDAO')
try:
issue_json = subprocess.check_output(["gh", "--repo", repository,
"issue", "view", "--json", "body", issue_id])
p = subprocess.run(["gh", "--repo", repository, "issue", "view", "--json", "body", issue_id],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except subprocess.CalledProcessError as err:
print(f"Unable to access issue #{issue_id}:\nrc={err.returncode}")
print(f"stdout:\n------\n{p.stdout}")
print(f"stderr:\n------\n{p.stderr}")
return ERROR

issue_body = json.loads(issue_json)["body"]
print(f"stdout:\n------\n{p.stdout}")
print(f"stderr:\n------\n{p.stderr}")

issue_body = json.loads(p.stdout)["body"]

poem_id = ""

Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/openmdao_latest_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
PETSc: True
PYOPTSPARSE: true
SNOPT: true
BANDIT: true
BUILD_DOCS: true

# test latest versions on ubuntu
Expand Down Expand Up @@ -352,6 +353,28 @@ jobs:
grep '^0 unique deprecation warnings' $RPT_FILE
- name: Scan for security issues
if: matrix.BANDIT
id: bandit
continue-on-error: true
run: |
python -m pip install bandit
echo "============================================================="
echo "Run bandit scan for high/medium severity issues"
echo "============================================================="
cd ${{ github.workspace }}
python -m bandit -c bandit.yml -ll -r openmdao
- name: Slack security issue
if: steps.bandit.outcome == 'failure'
uses: act10ns/[email protected]
with:
webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
status: 'warning'
message:
Security issue found on `${{ matrix.NAME }}` build.
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

- name: Slack env change
if: steps.env_info.outputs.errors != ''
uses: act10ns/[email protected]
Expand Down
11 changes: 0 additions & 11 deletions .github/workflows/openmdao_test_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,6 @@ jobs:
- name: Scan for security issues
if: matrix.BANDIT
id: bandit
continue-on-error: true
run: |
python -m pip install bandit
echo "============================================================="
Expand All @@ -735,16 +734,6 @@ jobs:
cd ${{ github.workspace }}
python -m bandit -c bandit.yml -ll -r openmdao
- name: Slack security issue
if: steps.bandit.outcome == 'failure'
uses: act10ns/[email protected]
with:
webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
status: ${{ steps.bandit.outcome }}
message:
Security issue found on `${{ matrix.NAME }}` build.
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

coveralls:
name: Finish coverage
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/openmdao_update_poem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ name: Update Associated POEM

on:
pull_request:
types: [ opened, reopened, closed ]
types: [ opened, reopened, closed, synchronize ]
branches: [ master ]

permissions: {}
# permissions: {}

jobs:

check_for_poem:
if: github.event.action == 'opened' || github.event.action == 'reopened' || github.event.pull_request.merged
if: github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize' || github.event.pull_request.merged

runs-on: ubuntu-latest

Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
fi
- name: Comment on PR
if: (github.event.action == 'opened' || github.event.action == 'reopened') && steps.check_for_poem.outputs.POEM_ID != ''
if: (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize') && steps.check_for_poem.outputs.POEM_ID != ''
env:
POEM_ID: ${{ steps.check_for_poem.outputs.POEM_ID }}
POEM_URL: ${{ github.server_url }}/${{ github.repository_owner }}/POEMs/blob/master/POEM_${{ steps.check_for_poem.outputs.POEM_ID }}.md
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![PyPI version][10]][11]
[![PyPI Monthly Downloads][12]][11]


# [OpenMDAO][0]

OpenMDAO is an open-source high-performance computing platform for
Expand Down
2 changes: 1 addition & 1 deletion openmdao/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '3.32.1-dev'
__version__ = '3.33.1-dev'

INF_BOUND = 1.0E30
19 changes: 16 additions & 3 deletions openmdao/components/ks_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,13 @@ def initialize(self):
self.options.declare('width', types=int, default=1, desc='Width of constraint vector.')
self.options.declare('vec_size', types=int, default=1,
desc='The number of rows to independently aggregate.')
self.options.declare('minimum', types=bool, default=False,
desc='Return the minimum instead of the maximum by multiplying both '
'the inputs and output by -1. It is not recommended to use both '
'this option and the lower_flag option (it will return the '
'negative of the aggregated max.)')
self.options.declare('lower_flag', types=bool, default=False,
desc="Set to True to reverse sign of input constraints.")
desc='Set to True to reverse sign of input constraints.')
self.options.declare('rho', 50.0, desc="Constraint Aggregation Factor.")
self.options.declare('upper', 0.0, desc="Upper bound for constraint, default is zero.")
self.options.declare('add_constraint', types=bool, default=False,
Expand Down Expand Up @@ -229,8 +234,15 @@ def compute(self, inputs, outputs):
con_val = inputs['g'] - opt['upper']
if opt['lower_flag']:
con_val = -con_val
if opt['minimum']:
con_val = -con_val

ks_val = KSfunction.compute(con_val, opt['rho'])

outputs['KS'] = KSfunction.compute(con_val, opt['rho'])
if opt['minimum']:
ks_val = -ks_val

outputs['KS'] = ks_val

def compute_partials(self, inputs, partials):
"""
Expand All @@ -244,11 +256,12 @@ def compute_partials(self, inputs, partials):
Sub-jac components written to partials[output_name, input_name].
"""
opt = self.options
width = opt['width']

con_val = inputs['g'] - opt['upper']
if opt['lower_flag']:
con_val = -con_val
if opt['minimum']:
con_val = -con_val

derivs = KSfunction.derivatives(con_val, opt['rho'])[0]

Expand Down
63 changes: 62 additions & 1 deletion openmdao/components/tests/test_ks_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import openmdao.api as om
from openmdao.test_suite.components.simple_comps import DoubleArrayComp
from openmdao.test_suite.test_examples.beam_optimization.multipoint_beam_stress import MultipointBeamGroup
from openmdao.utils.assert_utils import assert_near_equal
from openmdao.utils.assert_utils import assert_near_equal, assert_check_partials
from openmdao.utils.testing_utils import force_check_partials


Expand Down Expand Up @@ -320,6 +320,67 @@ def test_units(self):

assert_near_equal(prob.get_val('ks.KS', indices=0), np.amax(prob.get_val('x')), tolerance=1e-8)

def test_minimum(self):

n = 10

model = om.Group()

model.add_subsystem('ks', om.KSComp(width=n, minimum=True), promotes_inputs=[('g', 'x')])
model.set_input_defaults('x', range(n))

prob = om.Problem(model=model)
prob.setup()
prob.run_model()

assert_near_equal(prob.get_val('ks.KS', indices=0), np.amin(prob.get_val('x')), tolerance=1e-8)

def test_minimum_partials(self):

n = 10

model = om.Group()

model.add_subsystem('ks', om.KSComp(width=n, minimum=True), promotes_inputs=[('g', 'x')])
model.set_input_defaults('x', range(n))

prob = om.Problem(model=model)
prob.setup(force_alloc_complex=True)
prob.run_model()

partials = force_check_partials(prob, includes=['ks'], out_stream=None, method="cs", step=1e-200)
assert_check_partials(partials)

def test_minimum_and_lower_flag(self):

n = 10

model = om.Group()

model.add_subsystem('ks', om.KSComp(width=n, minimum=True, lower_flag=True), promotes_inputs=[('g', 'x')])
model.set_input_defaults('x', range(n))

prob = om.Problem(model=model)
prob.setup()
prob.run_model()

assert_near_equal(prob.get_val('ks.KS', indices=0), -np.amax(prob.get_val('x')), tolerance=1e-8)

def test_minimum_and_lower_flag_partials(self):

n = 10

model = om.Group()

model.add_subsystem('ks', om.KSComp(width=n, minimum=True, lower_flag=True), promotes_inputs=[('g', 'x')])
model.set_input_defaults('x', range(n))

prob = om.Problem(model=model)
prob.setup(force_alloc_complex=True)
prob.run_model()

partials = force_check_partials(prob, includes=['ks'], out_stream=None, method="cs", step=1e-200)
assert_check_partials(partials)

if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@
"# modify the constraint and run again\n",
"\n",
"model.set_constraint_options(name='con1', upper=-1.0)\n",
"prob.setup()\n",
"prob.run_driver()\n",
"print(f\"con1 = {prob.get_val('con1')}\")"
]
Expand Down
2 changes: 1 addition & 1 deletion openmdao/utils/code_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def __setstate__(self, state):
The state of this object.
"""
self.__dict__.update(state)
self._func = eval(state['_func'])
self._func = eval(state['_func']) # nosec

def _getsrc(self):
if self._src is None:
Expand Down
7 changes: 6 additions & 1 deletion openmdao/utils/relevance.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,8 @@ def is_relevant_system(self, name):
"""
Return True if the given named system is relevant.
Returns False if system has no subsystems with outputs.
Parameters
----------
name : str
Expand All @@ -811,7 +813,10 @@ def is_relevant_system(self, name):
if not self._active:
return True

return self._current_rel_sarray[self._sys2idx[name]]
try:
return self._current_rel_sarray[self._sys2idx[name]]
except KeyError:
return False

def filter(self, systems, relevant=True):
"""
Expand Down
20 changes: 20 additions & 0 deletions openmdao/utils/tests/test_relevance.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,23 @@ def compute_jacvec_product(self, inputs, d_inputs, d_outputs, mode):
prob.run_model()
chk = prob.check_totals(of='b', wrt='a', show_only_incorrect=True)
assert_check_totals(chk)

class TestRelevanceEmptyGroups(unittest.TestCase):
def test_emptygroup(self):
'''Tests that relevance checks do not error if empty groups are present'''
prob = om.Problem()
model = prob.model

model.add_subsystem('empy_group', om.Group(), promotes=['*'])
grp2: om.Group = model.add_subsystem('non_empty_group', om.Group(), promotes=['*'])
grp2.add_subsystem('idv', om.IndepVarComp('x', val=1), promotes=['*'])
grp2.add_subsystem('comp', om.ExecComp('y=2*x**2'), promotes=['*'])
model.add_design_var('x')
model.add_objective('y')

prob.driver = om.ScipyOptimizeDriver()

prob.setup(force_alloc_complex=True)
prob.run_driver()

assert_check_totals(prob.check_totals(method='cs', out_stream=None))
Loading

0 comments on commit 332aed3

Please sign in to comment.