Skip to content

Fix component decorator return value#1296

Merged
jsiirola merged 1 commit intoPyomo:masterfrom
jsiirola:decorator-fix
Feb 17, 2020
Merged

Fix component decorator return value#1296
jsiirola merged 1 commit intoPyomo:masterfrom
jsiirola:decorator-fix

Conversation

@jsiirola
Copy link
Copy Markdown
Member

Fixes #N/A

Summary/Motivation:

Currently, the "@model.Constraint()" notation masks the decorated function:

@model.Constraint()
def foo(m):
    return m.x >= 0

results in foo being declared in the local namespace, but type(foo) is None. This PR fixes it so that foo is the original rule function.

Changes proposed in this PR:

  • Fix return value for component decorator

Legal Acknowledgement

By contributing to this software project, I agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

This corrects the "@model.Constraint()" notation so that the decorated
function still appears in the calling namespace.
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 16, 2020

Codecov Report

Merging #1296 into master will decrease coverage by 1.65%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1296      +/-   ##
==========================================
- Coverage   70.95%   69.30%   -1.66%     
==========================================
  Files         534      533       -1     
  Lines       81016    81276     +260     
==========================================
- Hits        57484    56325    -1159     
- Misses      23532    24951    +1419     
Impacted Files Coverage Δ
pyomo/opt/parallel/pyro.py 18.34% <0.00%> (-71.56%) ⬇️
pyomo/pysp/scenariotree/action_manager_pyro.py 18.12% <0.00%> (-63.16%) ⬇️
...mo/pysp/scenariotree/manager_solver_worker_pyro.py 27.53% <0.00%> (-60.87%) ⬇️
pyomo/solvers/plugins/smanager/pyro.py 23.01% <0.00%> (-59.53%) ⬇️
pyomo/pysp/scenariotree/manager_worker_pyro.py 21.64% <0.00%> (-59.28%) ⬇️
pyomo/pysp/scenariotree/server_pyro.py 22.88% <0.00%> (-55.73%) ⬇️
pyomo/pysp/scenariotree/manager.py 51.29% <0.00%> (-36.87%) ⬇️
examples/mpec/munson1d.py 73.39% <0.00%> (-26.61%) ⬇️
pyomo/pysp/scenariotree/manager_solver.py 69.97% <0.00%> (-20.68%) ⬇️
pyomo/scripting/pyro_mip_server.py 39.56% <0.00%> (-17.99%) ⬇️
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d9229cf...f597faa. Read the comment docs.

@qtothec
Copy link
Copy Markdown
Contributor

qtothec commented Feb 17, 2020

This certainly makes sense, although I'm surprised that anyone noticed.

@jsiirola jsiirola merged commit 4e0f78d into Pyomo:master Feb 17, 2020
@jsiirola jsiirola deleted the decorator-fix branch February 17, 2020 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants