Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulate PR 3214 #71

Merged
merged 41 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
bfdfc00
Added minimum option to KS comp and tests
eytanadler May 9, 2024
816ab2f
Fix pep8
eytanadler May 10, 2024
f860d2a
Merge branch 'master' into ks_min
swryan May 22, 2024
f7ca263
Let bandit fail test workflow; issue warning on latest workflow
swryan May 30, 2024
e9c83e7
only run bandit on one job in latest workflow
swryan May 31, 2024
93859b4
newline
swryan May 31, 2024
0abf45e
rm perm
swryan May 31, 2024
1675e3b
rm perm
swryan May 31, 2024
97faba7
sync
swryan May 31, 2024
83bb310
print
swryan May 31, 2024
4097570
Merge branch 'master' into 3260_bandit
swryan May 31, 2024
87eeb2a
Revert "rm perm"
swryan May 31, 2024
811a5ae
remove unnecessary setup() from doc page
swryan Jun 4, 2024
253921b
Merge pull request #3261 from swryan/3260_bandit
swryan Jun 4, 2024
18e9e76
release notes for 3.33.0
robfalck Jun 4, 2024
c06242d
Merge pull request #3229 from eytanadler/ks_min
swryan Jun 4, 2024
d44e6ab
Merge pull request #3263 from swryan/3262_docs
swryan Jun 4, 2024
afa7d00
fix relevance for empty groups
Jun 5, 2024
4db3f82
added assert check totals
Jun 6, 2024
435b6df
fix tests
Jun 7, 2024
cbdbf61
fix docstring
swryan Jun 7, 2024
8b34cb9
Merge pull request #2 from swryan/relevancy_check_empty_subsystems
andrewellis55 Jun 7, 2024
b31e346
Merge pull request #3265 from andrewellis55/relevancy_check_empty_sub…
swryan Jun 7, 2024
9b598cd
Merge branch 'master' into 3.33.0
swryan Jun 7, 2024
f3fb049
Update release notes for 3.33.0
swryan Jun 7, 2024
e10818d
Increment version for 3.33.0 release
swryan Jun 7, 2024
8b09077
Merge pull request #3270 from swryan/3.33.0
swryan Jun 7, 2024
ce1b2ab
increment version to 3.33.1-dev
swryan Jun 7, 2024
19959dc
Merge pull request #3271 from swryan/3.33.1-dev
swryan Jun 10, 2024
5cde34f
Merge branch 'master' into poem_integ
swryan Jun 10, 2024
4fa0cf5
err
swryan Jun 10, 2024
dc631c3
sync
swryan Jun 10, 2024
add8851
sync-action
swryan Jun 10, 2024
425d327
stderr
swryan Jun 10, 2024
435331c
pprint
swryan Jun 10, 2024
adb2277
shell
swryan Jun 10, 2024
319a191
repo
swryan Jun 10, 2024
1adf6c3
run
swryan Jun 10, 2024
a83af3f
repo
swryan Jun 10, 2024
6e856ca
replace
swryan Jun 10, 2024
163051e
msg
swryan Jun 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading