From 24ec6bc04795e81108b8882ca5a3ada20050e554 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Wed, 18 Dec 2024 07:07:19 -0700 Subject: [PATCH 1/8] Do not start the SAS session until needed (for .available or .solve) --- pyomo/solvers/plugins/solvers/SAS.py | 41 +++++++++++++++----------- pyomo/solvers/tests/checks/test_SAS.py | 15 ++++++---- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/pyomo/solvers/plugins/solvers/SAS.py b/pyomo/solvers/plugins/solvers/SAS.py index d7b09e29fde..572f091a9e6 100644 --- a/pyomo/solvers/plugins/solvers/SAS.py +++ b/pyomo/solvers/plugins/solvers/SAS.py @@ -195,7 +195,9 @@ def _presolve(self, *args, **kwds): def available(self, exception_flag=False): """True if the solver is available""" - return self._python_api_exists + if not self._python_api_exists: + return False + return self.start_sas_session() is not None def _has_integer_variables(self): """True if the problem has integer variables.""" @@ -285,12 +287,7 @@ def __init__(self, **kwds): # Store other options for the SAS session self._session_options = kwds - - # Create the session - try: - self._sas_session = self._sas.SASsession(**self._session_options) - except: - self._sas_session = None + self._sas_session = None def __del__(self): # Close the session, if we created one @@ -314,6 +311,15 @@ def _create_statement_str(self, statement): def sas_version(self): return self._sasver + def start_sas_session(self): + if self._sas_session is None: + # Create (and cache) the session + try: + self._sas_session = self._sas.SASsession(**self._session_options) + except: + pass + return self._sas_session + def _apply_solver(self): """ "Prepare the options and run the solver. Then store the data to be returned.""" logger.debug("Running SAS") @@ -374,10 +380,7 @@ def _apply_solver(self): sas_options = "option notes nonumber nodate nosource pagesize=max;" # Get the current SAS session, submit the code and return the results - if not self._sas_session: - sas = self._sas_session = self._sas.SASsession(**self._session_options) - else: - sas = self._sas_session + sas = self.start_sas_session() # Find the version of 9.4 we are using self._sasver = sas.sasver @@ -585,12 +588,7 @@ def __init__(self, **kwds): self._python_api_exists = True self._session_options = kwds - - # Create the session - try: - self._sas_session = self._sas.CAS(**self._session_options) - except: - self._sas_session = None + self._sas_session = None def __del__(self): # Close the session, if we created one @@ -598,6 +596,15 @@ def __del__(self): self._sas_session.close() del self._sas_session + def start_sas_session(self): + if self._sas_session is None: + # Create (and cache) the session + try: + self._sas_session = self._sas.CAS(**self._session_options) + except: + pass + return self._sas_session + def _uploadMpsFile(self, s, unique): # Declare a unique table name for the mps table mpsdata_table_name = "mps" + unique diff --git a/pyomo/solvers/tests/checks/test_SAS.py b/pyomo/solvers/tests/checks/test_SAS.py index 6dd662bdb21..65f466508e8 100644 --- a/pyomo/solvers/tests/checks/test_SAS.py +++ b/pyomo/solvers/tests/checks/test_SAS.py @@ -26,7 +26,7 @@ Suffix, ) from pyomo.opt.results import SolverStatus, TerminationCondition, ProblemSense -from pyomo.opt import SolverFactory, check_available_solvers +from pyomo.opt import SolverFactory import warnings CFGFILE = os.environ.get("SAS_CFG_FILE_PATH", None) @@ -38,7 +38,10 @@ } -sas_available = check_available_solvers("sas") +try: + sas94_available = SolverFactory('_sas94').available() +except: + sas94_available = False class SASTestAbc: @@ -292,7 +295,7 @@ def test_solver_with_milp(self): ) -@unittest.skipIf(not sas_available, "The SAS solver is not available") +@unittest.skipIf(not sas94_available, "The SAS94 solver interface is not available") class SASTestLP94(SASTestLP, unittest.TestCase): @mock.patch( "pyomo.solvers.plugins.solvers.SAS.SAS94.sas_version", @@ -325,7 +328,7 @@ def test_solver_error(self, submit_mock, symget_mock): self.assertEqual(results.solver.status, SolverStatus.error) -# @unittest.skipIf(not sas_available, "The SAS solver is not available") +# @unittest.skipIf(not sascas_available, "The SAS solver is not available") @unittest.skip("Tests not yet configured for SAS Viya interface.") class SASTestLPCAS(SASTestLP, unittest.TestCase): solver_io = "_sascas" @@ -526,13 +529,13 @@ def test_solver_warmstart_capable(self): self.assertTrue(self.opt_sas.warm_start_capable()) -# @unittest.skipIf(not sas_available, "The SAS solver is not available") +# @unittest.skipIf(not sas94_available, "The SAS solver is not available") @unittest.skip("MILP94 tests disabled.") class SASTestMILP94(SASTestMILP, unittest.TestCase): pass -# @unittest.skipIf(not sas_available, "The SAS solver is not available") +# @unittest.skipIf(not sascas_available, "The SAS solver is not available") @unittest.skip("Tests not yet configured for SAS Viya interface.") class SASTestMILPCAS(SASTestMILP, unittest.TestCase): solver_io = "_sascas" From 5ef19dd6ac17b6eeb9870e7c3c796fb10a6a5029 Mon Sep 17 00:00:00 2001 From: Miranda Mundt Date: Tue, 21 Jan 2025 16:02:56 -0700 Subject: [PATCH 2/8] Big Wheel of Misfortune - A Practice in Reviewing Old Issues --- scripts/admin/README.md | 54 ++++++++++++++-- scripts/admin/bwom.py | 136 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 185 insertions(+), 5 deletions(-) create mode 100644 scripts/admin/bwom.py diff --git a/scripts/admin/README.md b/scripts/admin/README.md index 50ad2020b94..d7ec9fb3231 100644 --- a/scripts/admin/README.md +++ b/scripts/admin/README.md @@ -1,15 +1,19 @@ -# Contributors Script +# Admin Scripts + +-------- + +## Contributors Script The `contributors.py` script is intended to be used to determine contributors to a public GitHub repository within a given time frame. -## Requirements +### Requirements -1. Python 3.7+ +1. Python 3.9+ 1. [PyGithub](https://pypi.org/project/PyGithub/) 1. A [GitHub Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) with `repo` access, exported to the environment variable `GH_TOKEN` -## Usage +### Usage ``` Usage: contributors.py @@ -21,8 +25,48 @@ ALSO REQUIRED: Please generate a GitHub token (with repo permissions) and export Visit GitHub's official documentation for more details. ``` -## Results +### Results A list of contributors will print to the terminal upon completion. More detailed information, including authors, committers, reviewers, and pull requests, can be found in the `contributors-start_date-end_date.json` generated file. + + +---------- + +## Big Wheel of Misfortune + +The `bwom.py` script is intended to be used during weekly Dev Calls to generate +a list of random open issues so developers can more proactively review issues +in the backlog. + +### Requirements + +1. Python 3.9+ +1. [PyGithub](https://pypi.org/project/PyGithub/) +1. A [GitHub Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) with `repo` access, exported to the environment variable `GH_TOKEN` + +### Usage + +``` +Usage: bwom.py [num_issues] + : the GitHub organization/repository combo (e.g., Pyomo/pyomo) + [Number of issues] : optional number of random open issues to return (default is 5) + +ALSO REQUIRED: Please generate a GitHub token (with repo permissions) and export to the environment variable GH_TOKEN. + Visit GitHub's official documentation for more details. +``` + +### Results + +A list of `n` random open issues (default is 5) on the target repository. +This list includes the issue number, title, and URL. For example: + +``` +Randomly selected open issues from Pyomo/pyomo: +- Issue #2087: Add Installation Environment Test (URL: https://github.com/Pyomo/pyomo/issues/2087) +- Issue #1310: Pynumero.sparse transpose (URL: https://github.com/Pyomo/pyomo/issues/1310) +- Issue #2218: cyipopt does not support `symbolic_solver_labels` or `load_solutions=False` (URL: https://github.com/Pyomo/pyomo/issues/2218) +- Issue #2123: k_aug interface in Pyomo sensitivity toolbox reports wrong answer (URL: https://github.com/Pyomo/pyomo/issues/2123) +- Issue #1761: slow quadratic constraint creation (URL: https://github.com/Pyomo/pyomo/issues/1761) +``` diff --git a/scripts/admin/bwom.py b/scripts/admin/bwom.py new file mode 100644 index 00000000000..d3ff324cdd3 --- /dev/null +++ b/scripts/admin/bwom.py @@ -0,0 +1,136 @@ +# ___________________________________________________________________________ +# +# Pyomo: Python Optimization Modeling Objects +# Copyright (c) 2008-2024 +# National Technology and Engineering Solutions of Sandia, LLC +# Under the terms of Contract DE-NA0003525 with National Technology and +# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain +# rights in this software. +# This software is distributed under the 3-clause BSD License. +# ___________________________________________________________________________ + + +""" +This script is intended to query the GitHub REST API and get a list of open +issues for a given repository, returning a random selection of n issues. + +We colloquially call this the "Big Wheel of Misfortune" (BWOM) +""" + +import sys +import random +import os + +from github import Github, Auth + + +def get_random_open_issues(repository, number_to_return): + """ + Return a random selection of open issues from a repository. + + Parameters + ---------- + repository : String + The org/repo combination for target repository (GitHub). E.g., + IDAES/idaes-pse. + number_to_return : int + The number of random open issues to return. + + Returns + ------- + random_issues : List + A list of dictionaries containing information about randomly selected open issues. + """ + # Collect the authorization token from the user's environment + token = os.environ.get('GH_TOKEN') + auth_token = Auth.Token(token) + # Create a connection to GitHub + gh = Github(auth=auth_token) + # Create a repository object for the requested repository + repo = gh.get_repo(repository) + # Get all open issues + open_issues = repo.get_issues(state='open') + open_issues_list = [issue for issue in open_issues] + + # Randomly select the specified number of issues + random_issues = random.sample( + open_issues_list, min(number_to_return, len(open_issues_list)) + ) + + return random_issues + + +def print_big_wheel(): + """Prints a specified ASCII art representation of a big wheel.""" + wheel = [ + " . __", + " / \\ . ' || ' .", + " )J( .` || `.", + " (8)7) . \\ || / .", + " (') .'/ _ \\ .-''-. / _ \\", + " (=) .' J `- .' .--. '. -` L", + " (') .' F======' ((<>)) '======J", + " )J(' L '. `||' .' F", + " (7(8) \\ _.- `-||-' -._ /", + " \\' . / || \\ .", + " / | . / || \\ .", + " / | ` . _||_ . `", + " / |___________ _.-||_________", + " (()\\.'| ___.....'''' ||._ .'", + " \\.`- .'. /__\\/ .'|", + ".'_______________________________.' ||", + " |'---------------------------'|==.||", + " ||.' || ||.' ||", + " ||===========================|| (__)", + " || ||", + " (__) LGB (__)", + " Credit: ascii.co.uk/art/spinningwheel", + ] + for line in wheel: + print(line) + + +def main(): + if len(sys.argv) < 2 or len(sys.argv) > 3: + print(f"Usage: {sys.argv[0]} [num_issues]") + print( + " : the GitHub organization/repository combo (e.g., Pyomo/pyomo)" + ) + print( + " [Number of issues] : optional number of random open issues to return (default is 5)" + ) + print("") + print( + "ALSO REQUIRED: Please generate a GitHub token (with repo permissions) " + "and export to the environment variable GH_TOKEN." + ) + print(" Visit GitHub's official documentation for more details.") + sys.exit(1) + + repository = sys.argv[1] + if len(sys.argv) == 3: + try: + num_issues = int(sys.argv[2]) + if num_issues <= 0: + raise (ValueError("Need a positive number; why did you try <= 0?")) + except ValueError as e: + print( + "*** ERROR: You did something weird when declaring the number of issues. Defaulting to 5.\n" + f"(For posterity, this is the error that was returned: {e})\n" + ) + num_issues = 5 + else: + num_issues = 5 + + print("Spinning the Big Wheel of Misfortune...\n") + print_big_wheel() + + random_issues = get_random_open_issues(repository, num_issues) + + print(f"\nRandomly selected open issues from {repository}:") + for issue in random_issues: + print(f"- Issue #{issue.number}: {issue.title} (URL: {issue.html_url})") + + +if __name__ == '__main__': + main() From f6bcd15790b9a1b69d4d993c09868f43ef4c0aae Mon Sep 17 00:00:00 2001 From: John Siirola Date: Wed, 29 Jan 2025 08:39:36 -0700 Subject: [PATCH 3/8] Uppdate Qt tests to avoid core dump without active X11 session --- pyomo/contrib/viewer/tests/test_qt.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyomo/contrib/viewer/tests/test_qt.py b/pyomo/contrib/viewer/tests/test_qt.py index 9d18cc388df..506b09844f4 100644 --- a/pyomo/contrib/viewer/tests/test_qt.py +++ b/pyomo/contrib/viewer/tests/test_qt.py @@ -23,6 +23,12 @@ """ UI Tests """ +# The pytest-qt plugin can generate exceptions / core dumps when it is +# run in a terminal (without an axtive X11 screen). Setting the +# QT_QPA_PLATFORM environemnt variable *before* initializing Qt can work +# around this error (see https://stackoverflow.com/a/74719383): +import os +os.environ['QT_QPA_PLATFORM'] = 'offscreen' from pyomo.environ import ( ConcreteModel, From 4f28012060d52525bd70dba590941b8e6a395455 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Wed, 29 Jan 2025 08:56:06 -0700 Subject: [PATCH 4/8] NFC: Updates for Black 25.1.0 --- pyomo/common/tests/test_config.py | 1 + pyomo/contrib/community_detection/event_log.py | 2 +- pyomo/contrib/incidence_analysis/config.py | 3 +-- pyomo/contrib/incidence_analysis/incidence.py | 3 +-- pyomo/contrib/incidence_analysis/visualize.py | 4 +--- pyomo/contrib/mindtpy/tests/MINLP4_simple.py | 2 +- .../contrib/mindtpy/tests/constraint_qualification_example.py | 2 +- pyomo/contrib/mindtpy/tests/online_doc_example.py | 2 +- .../reaction_kinetics/simple_reaction_parmest_example.py | 2 +- .../contrib/parmest/examples/rooney_biegler/rooney_biegler.py | 4 ++-- pyomo/contrib/parmest/examples/semibatch/parallel_example.py | 2 +- pyomo/contrib/parmest/examples/semibatch/semibatch.py | 4 ++-- pyomo/contrib/sensitivity_toolbox/examples/rooney_biegler.py | 4 ++-- .../contrib/sensitivity_toolbox/tests/test_k_aug_interface.py | 3 +-- pyomo/contrib/viewer/qt.py | 2 +- pyomo/contrib/viewer/tests/test_qt.py | 1 + pyomo/solvers/plugins/solvers/mosek_direct.py | 2 +- .../piecewise_linear/problems/concave_multi_vararray1.py | 2 +- .../piecewise_linear/problems/concave_multi_vararray2.py | 2 +- pyomo/solvers/tests/piecewise_linear/problems/concave_var.py | 2 +- .../tests/piecewise_linear/problems/concave_vararray.py | 2 +- .../tests/piecewise_linear/problems/convex_multi_vararray1.py | 2 +- .../tests/piecewise_linear/problems/convex_multi_vararray2.py | 2 +- pyomo/solvers/tests/piecewise_linear/problems/convex_var.py | 2 +- .../tests/piecewise_linear/problems/convex_vararray.py | 2 +- pyomo/util/check_units.py | 2 +- 26 files changed, 29 insertions(+), 32 deletions(-) diff --git a/pyomo/common/tests/test_config.py b/pyomo/common/tests/test_config.py index 67bb93a7224..88e0706ba05 100644 --- a/pyomo/common/tests/test_config.py +++ b/pyomo/common/tests/test_config.py @@ -88,6 +88,7 @@ def _display(obj, *args): class GlobalClass(object): "test class for test_known_types" + pass diff --git a/pyomo/contrib/community_detection/event_log.py b/pyomo/contrib/community_detection/event_log.py index 767ff0f50f5..13226ade9d5 100644 --- a/pyomo/contrib/community_detection/event_log.py +++ b/pyomo/contrib/community_detection/event_log.py @@ -9,7 +9,7 @@ # This software is distributed under the 3-clause BSD License. # ___________________________________________________________________________ -""" Logger function for community_graph.py """ +"""Logger function for community_graph.py""" from logging import getLogger from pyomo.core import Constraint, Objective, Var diff --git a/pyomo/contrib/incidence_analysis/config.py b/pyomo/contrib/incidence_analysis/config.py index 50ad4e48f3e..a8616dce00a 100644 --- a/pyomo/contrib/incidence_analysis/config.py +++ b/pyomo/contrib/incidence_analysis/config.py @@ -8,8 +8,7 @@ # rights in this software. # This software is distributed under the 3-clause BSD License. # ___________________________________________________________________________ -"""Configuration options for incidence graph generation -""" +"""Configuration options for incidence graph generation""" import enum from pyomo.common.config import ConfigDict, ConfigValue, InEnum diff --git a/pyomo/contrib/incidence_analysis/incidence.py b/pyomo/contrib/incidence_analysis/incidence.py index 48160bc793e..4f8f8bd5c3b 100644 --- a/pyomo/contrib/incidence_analysis/incidence.py +++ b/pyomo/contrib/incidence_analysis/incidence.py @@ -8,8 +8,7 @@ # rights in this software. # This software is distributed under the 3-clause BSD License. # ___________________________________________________________________________ -"""Functionality for identifying variables that participate in expressions -""" +"""Functionality for identifying variables that participate in expressions""" from contextlib import nullcontext diff --git a/pyomo/contrib/incidence_analysis/visualize.py b/pyomo/contrib/incidence_analysis/visualize.py index af1bdbbb918..a6c88f80a2c 100644 --- a/pyomo/contrib/incidence_analysis/visualize.py +++ b/pyomo/contrib/incidence_analysis/visualize.py @@ -8,9 +8,7 @@ # rights in this software. # This software is distributed under the 3-clause BSD License. # ___________________________________________________________________________ -"""Module for visualizing results of incidence graph or matrix analysis - -""" +"""Module for visualizing results of incidence graph or matrix analysis""" from pyomo.contrib.incidence_analysis.config import IncidenceOrder from pyomo.contrib.incidence_analysis.interface import ( IncidenceGraphInterface, diff --git a/pyomo/contrib/mindtpy/tests/MINLP4_simple.py b/pyomo/contrib/mindtpy/tests/MINLP4_simple.py index 44b6c7df543..bd5a4c53e97 100644 --- a/pyomo/contrib/mindtpy/tests/MINLP4_simple.py +++ b/pyomo/contrib/mindtpy/tests/MINLP4_simple.py @@ -10,7 +10,7 @@ # ___________________________________________________________________________ # -*- coding: utf-8 -*- -""" Example 1 in Paper 'Using regularization and second order information in outer approximation for convex MINLP' +"""Example 1 in Paper 'Using regularization and second order information in outer approximation for convex MINLP' The expected optimal solution value is -56.981. diff --git a/pyomo/contrib/mindtpy/tests/constraint_qualification_example.py b/pyomo/contrib/mindtpy/tests/constraint_qualification_example.py index c0849094300..29546c4f8f9 100644 --- a/pyomo/contrib/mindtpy/tests/constraint_qualification_example.py +++ b/pyomo/contrib/mindtpy/tests/constraint_qualification_example.py @@ -10,7 +10,7 @@ # ___________________________________________________________________________ # -*- coding: utf-8 -*- -""" Example of constraint qualification. +"""Example of constraint qualification. The expected optimal solution value is 3. diff --git a/pyomo/contrib/mindtpy/tests/online_doc_example.py b/pyomo/contrib/mindtpy/tests/online_doc_example.py index 17a758552c0..207ecf7d945 100644 --- a/pyomo/contrib/mindtpy/tests/online_doc_example.py +++ b/pyomo/contrib/mindtpy/tests/online_doc_example.py @@ -9,7 +9,7 @@ # This software is distributed under the 3-clause BSD License. # ___________________________________________________________________________ -""" Example in the online doc. +"""Example in the online doc. The expected optimal solution value is 2.438447187191098. diff --git a/pyomo/contrib/parmest/examples/reaction_kinetics/simple_reaction_parmest_example.py b/pyomo/contrib/parmest/examples/reaction_kinetics/simple_reaction_parmest_example.py index 5c8a0219946..9a0309811a3 100644 --- a/pyomo/contrib/parmest/examples/reaction_kinetics/simple_reaction_parmest_example.py +++ b/pyomo/contrib/parmest/examples/reaction_kinetics/simple_reaction_parmest_example.py @@ -8,7 +8,7 @@ # rights in this software. # This software is distributed under the 3-clause BSD License. # ___________________________________________________________________________ -''' +''' Example from Y. Bard, "Nonlinear Parameter Estimation", (pg. 124) This example shows: diff --git a/pyomo/contrib/parmest/examples/rooney_biegler/rooney_biegler.py b/pyomo/contrib/parmest/examples/rooney_biegler/rooney_biegler.py index 9625ab32ea3..2dd3ba41007 100644 --- a/pyomo/contrib/parmest/examples/rooney_biegler/rooney_biegler.py +++ b/pyomo/contrib/parmest/examples/rooney_biegler/rooney_biegler.py @@ -10,8 +10,8 @@ # ___________________________________________________________________________ """ -Rooney Biegler model, based on Rooney, W. C. and Biegler, L. T. (2001). Design for -model parameter uncertainty using nonlinear confidence regions. AIChE Journal, +Rooney Biegler model, based on Rooney, W. C. and Biegler, L. T. (2001). Design for +model parameter uncertainty using nonlinear confidence regions. AIChE Journal, 47(8), 1794-1804. """ diff --git a/pyomo/contrib/parmest/examples/semibatch/parallel_example.py b/pyomo/contrib/parmest/examples/semibatch/parallel_example.py index d7cc497803e..962694385fc 100644 --- a/pyomo/contrib/parmest/examples/semibatch/parallel_example.py +++ b/pyomo/contrib/parmest/examples/semibatch/parallel_example.py @@ -10,7 +10,7 @@ # ___________________________________________________________________________ """ -The following script can be used to run semibatch parameter estimation in +The following script can be used to run semibatch parameter estimation in parallel and save results to files for later analysis and graphics. Example command: mpiexec -n 4 python parallel_example.py """ diff --git a/pyomo/contrib/parmest/examples/semibatch/semibatch.py b/pyomo/contrib/parmest/examples/semibatch/semibatch.py index b506d41d072..3bb576bb551 100644 --- a/pyomo/contrib/parmest/examples/semibatch/semibatch.py +++ b/pyomo/contrib/parmest/examples/semibatch/semibatch.py @@ -9,9 +9,9 @@ # This software is distributed under the 3-clause BSD License. # ___________________________________________________________________________ """ -Semibatch model, based on Nicholson et al. (2018). pyomo.dae: A modeling and +Semibatch model, based on Nicholson et al. (2018). pyomo.dae: A modeling and automatic discretization framework for optimization with di -erential and +erential and algebraic equations. Mathematical Programming Computation, 10(2), 187-223. """ import json diff --git a/pyomo/contrib/sensitivity_toolbox/examples/rooney_biegler.py b/pyomo/contrib/sensitivity_toolbox/examples/rooney_biegler.py index 3efb20bd44b..895f69338c7 100644 --- a/pyomo/contrib/sensitivity_toolbox/examples/rooney_biegler.py +++ b/pyomo/contrib/sensitivity_toolbox/examples/rooney_biegler.py @@ -22,8 +22,8 @@ # at the URL "https://github.com/IDAES/idaes-pse". ############################################################################## """ -Rooney Biegler model, based on Rooney, W. C. and Biegler, L. T. (2001). Design for -model parameter uncertainty using nonlinear confidence regions. AIChE Journal, +Rooney Biegler model, based on Rooney, W. C. and Biegler, L. T. (2001). Design for +model parameter uncertainty using nonlinear confidence regions. AIChE Journal, 47(8), 1794-1804. """ from pyomo.common.dependencies import pandas as pd diff --git a/pyomo/contrib/sensitivity_toolbox/tests/test_k_aug_interface.py b/pyomo/contrib/sensitivity_toolbox/tests/test_k_aug_interface.py index e941656a392..3bbe1b7f200 100644 --- a/pyomo/contrib/sensitivity_toolbox/tests/test_k_aug_interface.py +++ b/pyomo/contrib/sensitivity_toolbox/tests/test_k_aug_interface.py @@ -20,8 +20,7 @@ # This software is distributed under the 3-clause BSD License. # ____________________________________________________________________________ -""" -""" +""" """ import os import pyomo.common.unittest as unittest from io import StringIO diff --git a/pyomo/contrib/viewer/qt.py b/pyomo/contrib/viewer/qt.py index f2744fa2d56..54156489d68 100644 --- a/pyomo/contrib/viewer/qt.py +++ b/pyomo/contrib/viewer/qt.py @@ -21,7 +21,7 @@ # ___________________________________________________________________________ """ -Try to import PySide6, which is the current official Qt 6 Python interface. Then, +Try to import PySide6, which is the current official Qt 6 Python interface. Then, try PyQt5 if that doesn't work. If no compatible Qt Python interface is found, use some dummy classes to allow some testing. """ diff --git a/pyomo/contrib/viewer/tests/test_qt.py b/pyomo/contrib/viewer/tests/test_qt.py index 506b09844f4..1e219fa5a0a 100644 --- a/pyomo/contrib/viewer/tests/test_qt.py +++ b/pyomo/contrib/viewer/tests/test_qt.py @@ -28,6 +28,7 @@ # QT_QPA_PLATFORM environemnt variable *before* initializing Qt can work # around this error (see https://stackoverflow.com/a/74719383): import os + os.environ['QT_QPA_PLATFORM'] = 'offscreen' from pyomo.environ import ( diff --git a/pyomo/solvers/plugins/solvers/mosek_direct.py b/pyomo/solvers/plugins/solvers/mosek_direct.py index 025c71d36f0..5682ae69b2c 100644 --- a/pyomo/solvers/plugins/solvers/mosek_direct.py +++ b/pyomo/solvers/plugins/solvers/mosek_direct.py @@ -1068,7 +1068,7 @@ def _warm_start(self): for pyomo_var, mosek_var in self._pyomo_var_to_solver_var_map.items(): if pyomo_var.value is not None: self._solver_model.putxxslice( - self._whichsol, mosek_var, mosek_var + 1, [(pyomo_var.value)] + self._whichsol, mosek_var, mosek_var + 1, [pyomo_var.value] ) if (self._version[0] > 9) & (self._whichsol == mosek.soltype.itg): diff --git a/pyomo/solvers/tests/piecewise_linear/problems/concave_multi_vararray1.py b/pyomo/solvers/tests/piecewise_linear/problems/concave_multi_vararray1.py index 473b3328660..8c870538c99 100644 --- a/pyomo/solvers/tests/piecewise_linear/problems/concave_multi_vararray1.py +++ b/pyomo/solvers/tests/piecewise_linear/problems/concave_multi_vararray1.py @@ -14,7 +14,7 @@ | 7x+12 , -4 <= x <= -3 | 5x+6 , -3 <= x <= -2 | 3x+2 , -2 <= x <= -1 -f(x) = | 1 , -1 <= x <= 1 +f(x) = | 1 , -1 <= x <= 1 | -3x+2 , 1 <= x <= 2 | -5x+6 , 2 <= x <= 3 \ -7x+12, 3 <= x <= 4 diff --git a/pyomo/solvers/tests/piecewise_linear/problems/concave_multi_vararray2.py b/pyomo/solvers/tests/piecewise_linear/problems/concave_multi_vararray2.py index e6b57a4b652..b40233168e9 100644 --- a/pyomo/solvers/tests/piecewise_linear/problems/concave_multi_vararray2.py +++ b/pyomo/solvers/tests/piecewise_linear/problems/concave_multi_vararray2.py @@ -14,7 +14,7 @@ | 7x+12 , -4 <= x <= -3 | 5x+6 , -3 <= x <= -2 | 3x+2 , -2 <= x <= -1 -f(x) = | 1 , -1 <= x <= 1 +f(x) = | 1 , -1 <= x <= 1 | -3x+2 , 1 <= x <= 2 | -5x+6 , 2 <= x <= 3 \ -7x+12, 3 <= x <= 4 diff --git a/pyomo/solvers/tests/piecewise_linear/problems/concave_var.py b/pyomo/solvers/tests/piecewise_linear/problems/concave_var.py index b225cee4f87..04fd3d461be 100644 --- a/pyomo/solvers/tests/piecewise_linear/problems/concave_var.py +++ b/pyomo/solvers/tests/piecewise_linear/problems/concave_var.py @@ -14,7 +14,7 @@ | 7x+12 , -4 <= x <= -3 | 5x+6 , -3 <= x <= -2 | 3x+2 , -2 <= x <= -1 -f(x) = | 1 , -1 <= x <= 1 +f(x) = | 1 , -1 <= x <= 1 | -3x+2 , 1 <= x <= 2 | -5x+6 , 2 <= x <= 3 \ -7x+12, 3 <= x <= 4 diff --git a/pyomo/solvers/tests/piecewise_linear/problems/concave_vararray.py b/pyomo/solvers/tests/piecewise_linear/problems/concave_vararray.py index 727fc33ed80..559bdd36329 100644 --- a/pyomo/solvers/tests/piecewise_linear/problems/concave_vararray.py +++ b/pyomo/solvers/tests/piecewise_linear/problems/concave_vararray.py @@ -14,7 +14,7 @@ | 7x+12 , -4 <= x <= -3 | 5x+6 , -3 <= x <= -2 | 3x+2 , -2 <= x <= -1 -f(x) = | 1 , -1 <= x <= 1 +f(x) = | 1 , -1 <= x <= 1 | -3x+2 , 1 <= x <= 2 | -5x+6 , 2 <= x <= 3 \ -7x+12, 3 <= x <= 4 diff --git a/pyomo/solvers/tests/piecewise_linear/problems/convex_multi_vararray1.py b/pyomo/solvers/tests/piecewise_linear/problems/convex_multi_vararray1.py index 98f369b8c45..a1d2fb624d1 100644 --- a/pyomo/solvers/tests/piecewise_linear/problems/convex_multi_vararray1.py +++ b/pyomo/solvers/tests/piecewise_linear/problems/convex_multi_vararray1.py @@ -14,7 +14,7 @@ | -7x-12, -4 <= x <= -3 | -5x-6 , -3 <= x <= -2 | -3x-2 , -2 <= x <= -1 -f(x) = | 1 , -1 <= x <= 1 +f(x) = | 1 , -1 <= x <= 1 | 3x-2 , 1 <= x <= 2 | 5x-6 , 2 <= x <= 3 \ 7x-12 , 3 <= x <= 4 diff --git a/pyomo/solvers/tests/piecewise_linear/problems/convex_multi_vararray2.py b/pyomo/solvers/tests/piecewise_linear/problems/convex_multi_vararray2.py index c877bb6b72b..969a171261b 100644 --- a/pyomo/solvers/tests/piecewise_linear/problems/convex_multi_vararray2.py +++ b/pyomo/solvers/tests/piecewise_linear/problems/convex_multi_vararray2.py @@ -14,7 +14,7 @@ | -7x-12, -4 <= x <= -3 | -5x-6 , -3 <= x <= -2 | -3x-2 , -2 <= x <= -1 -f(x) = | 1 , -1 <= x <= 1 +f(x) = | 1 , -1 <= x <= 1 | 3x-2 , 1 <= x <= 2 | 5x-6 , 2 <= x <= 3 \ 7x-12 , 3 <= x <= 4 diff --git a/pyomo/solvers/tests/piecewise_linear/problems/convex_var.py b/pyomo/solvers/tests/piecewise_linear/problems/convex_var.py index 842ef50515b..05f7f20a6d1 100644 --- a/pyomo/solvers/tests/piecewise_linear/problems/convex_var.py +++ b/pyomo/solvers/tests/piecewise_linear/problems/convex_var.py @@ -14,7 +14,7 @@ | -7x-12, -4 <= x <= -3 | -5x-6 , -3 <= x <= -2 | -3x-2 , -2 <= x <= -1 -f(x) = | 1 , -1 <= x <= 1 +f(x) = | 1 , -1 <= x <= 1 | 3x-2 , 1 <= x <= 2 | 5x-6 , 2 <= x <= 3 \ 7x-12 , 3 <= x <= 4 diff --git a/pyomo/solvers/tests/piecewise_linear/problems/convex_vararray.py b/pyomo/solvers/tests/piecewise_linear/problems/convex_vararray.py index 087d0977ee0..4516965c5e5 100644 --- a/pyomo/solvers/tests/piecewise_linear/problems/convex_vararray.py +++ b/pyomo/solvers/tests/piecewise_linear/problems/convex_vararray.py @@ -14,7 +14,7 @@ | -7x-12, -4 <= x <= -3 | -5x-6 , -3 <= x <= -2 | -3x-2 , -2 <= x <= -1 -f(x) = | 1 , -1 <= x <= 1 +f(x) = | 1 , -1 <= x <= 1 | 3x-2 , 1 <= x <= 2 | 5x-6 , 2 <= x <= 3 \ 7x-12 , 3 <= x <= 4 diff --git a/pyomo/util/check_units.py b/pyomo/util/check_units.py index 6f95486c8cd..b27f701c61a 100644 --- a/pyomo/util/check_units.py +++ b/pyomo/util/check_units.py @@ -10,7 +10,7 @@ # __________________________________________________________________________ # # -""" Pyomo Units Checking Module +"""Pyomo Units Checking Module This module has some helpful methods to support checking units on Pyomo module objects. """ From db6655d1f5aaac9971b02d15d857a2cf981d9339 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Wed, 29 Jan 2025 08:59:52 -0700 Subject: [PATCH 5/8] NFC: Updates for Black 25.1.0 --- examples/gdp/circles/circles.py | 4 ++-- examples/gdp/farm_layout/farm_layout.py | 8 ++++---- examples/gdp/nine_process/small_process.py | 4 +--- examples/gdp/small_lit/basic_step.py | 4 ++-- examples/pyomo/columngeneration/cutting_stock.py | 2 +- examples/pyomo/sos/sos2_piecewise.py | 4 ++-- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/examples/gdp/circles/circles.py b/examples/gdp/circles/circles.py index a8b7a156fad..586cc7d3af3 100644 --- a/examples/gdp/circles/circles.py +++ b/examples/gdp/circles/circles.py @@ -10,8 +10,8 @@ # ___________________________________________________________________________ """ -The "circles" GDP example problem originating in Lee and Grossman (2000). The -goal is to choose a point to minimize a convex quadratic function over a set of +The "circles" GDP example problem originating in Lee and Grossman (2000). The +goal is to choose a point to minimize a convex quadratic function over a set of disjoint hyperspheres. """ diff --git a/examples/gdp/farm_layout/farm_layout.py b/examples/gdp/farm_layout/farm_layout.py index 1b232b9cfa6..487b3b73cd2 100644 --- a/examples/gdp/farm_layout/farm_layout.py +++ b/examples/gdp/farm_layout/farm_layout.py @@ -11,10 +11,10 @@ """ Farm layout example from Sawaya (2006). The goal is to determine optimal placements and dimensions for farm -plots of specified areas to minimize the perimeter of a minimal enclosing fence. This is a GDP problem with -some hyperbolic constraints to establish consistency of areas with length and width. The FLay05 and FLay06 -instances may take some time to solve; the others should be fast. Note that the Sawaya paper contains a -little bit of nonclarity: it references "height" variables which do not exist - we use "length" for the x-axis +plots of specified areas to minimize the perimeter of a minimal enclosing fence. This is a GDP problem with +some hyperbolic constraints to establish consistency of areas with length and width. The FLay05 and FLay06 +instances may take some time to solve; the others should be fast. Note that the Sawaya paper contains a +little bit of nonclarity: it references "height" variables which do not exist - we use "length" for the x-axis and "width" on the y-axis, and it also is unclear on the way the coordinates define the rectangles; we have decided that they are on the bottom-left and adapted the disjunction constraints to match. """ diff --git a/examples/gdp/nine_process/small_process.py b/examples/gdp/nine_process/small_process.py index 2abffef1af6..d5b7ac5d327 100644 --- a/examples/gdp/nine_process/small_process.py +++ b/examples/gdp/nine_process/small_process.py @@ -9,9 +9,7 @@ # This software is distributed under the 3-clause BSD License. # ___________________________________________________________________________ -"""Small process synthesis-inspired toy GDP example. - -""" +"""Small process synthesis-inspired toy GDP example.""" from pyomo.core import ConcreteModel, RangeSet, Var, Constraint, Objective from pyomo.core.expr.current import exp, log, sqrt diff --git a/examples/gdp/small_lit/basic_step.py b/examples/gdp/small_lit/basic_step.py index 2d9da97167c..1919a6e16f8 100644 --- a/examples/gdp/small_lit/basic_step.py +++ b/examples/gdp/small_lit/basic_step.py @@ -9,10 +9,10 @@ # This software is distributed under the 3-clause BSD License. # ___________________________________________________________________________ -""" Example from Section 3.2 in paper of Pseudo Basic Steps +"""Example from Section 3.2 in paper of Pseudo Basic Steps Ref: - Pseudo basic steps: bound improvement guarantees from Lagrangian + Pseudo basic steps: bound improvement guarantees from Lagrangian decomposition in convex disjunctive programming Papageorgiou and Trespalacios, 2017 diff --git a/examples/pyomo/columngeneration/cutting_stock.py b/examples/pyomo/columngeneration/cutting_stock.py index 2d9399c7db4..d331da9608b 100644 --- a/examples/pyomo/columngeneration/cutting_stock.py +++ b/examples/pyomo/columngeneration/cutting_stock.py @@ -16,7 +16,7 @@ Bradley, S.P., A.C. Hax, and T.L. Magnanti. 1977. Applied Mathematical Programming, Addison-Wesley, Reading, MA. Available: http://web.mit.edu/15.053/www/AMP.htm. -Data from https://en.wikipedia.org/wiki/Cutting_stock_problem +Data from https://en.wikipedia.org/wiki/Cutting_stock_problem ''' import pyomo.environ as pyo diff --git a/examples/pyomo/sos/sos2_piecewise.py b/examples/pyomo/sos/sos2_piecewise.py index 79195761f3d..1d952beb336 100644 --- a/examples/pyomo/sos/sos2_piecewise.py +++ b/examples/pyomo/sos/sos2_piecewise.py @@ -10,11 +10,11 @@ # ___________________________________________________________________________ """ -This example shows how to represent a piecewise function using +This example shows how to represent a piecewise function using Pyomo's built SOSConstraint component. The function is defined as: / 3x-2 , 1 <= x <= 2 -f(x) = | +f(x) = | \ 5x-6 , 2 <= x <= 3 """ From e3fef4a0a5b4930e6b5613e22d47275bef2cfac5 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Wed, 29 Jan 2025 09:22:36 -0700 Subject: [PATCH 6/8] NFC: fix typo --- pyomo/contrib/viewer/tests/test_qt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyomo/contrib/viewer/tests/test_qt.py b/pyomo/contrib/viewer/tests/test_qt.py index 1e219fa5a0a..2ef862b087c 100644 --- a/pyomo/contrib/viewer/tests/test_qt.py +++ b/pyomo/contrib/viewer/tests/test_qt.py @@ -25,7 +25,7 @@ """ # The pytest-qt plugin can generate exceptions / core dumps when it is # run in a terminal (without an axtive X11 screen). Setting the -# QT_QPA_PLATFORM environemnt variable *before* initializing Qt can work +# QT_QPA_PLATFORM environment variable *before* initializing Qt can work # around this error (see https://stackoverflow.com/a/74719383): import os From 6c9503b0c588cfb29be11f32ea509ee41a203610 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Wed, 29 Jan 2025 11:32:42 -0700 Subject: [PATCH 7/8] NFC: remove empty docstring Co-authored-by: Bethany Nicholson --- pyomo/contrib/sensitivity_toolbox/tests/test_k_aug_interface.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyomo/contrib/sensitivity_toolbox/tests/test_k_aug_interface.py b/pyomo/contrib/sensitivity_toolbox/tests/test_k_aug_interface.py index 3bbe1b7f200..1887d5847da 100644 --- a/pyomo/contrib/sensitivity_toolbox/tests/test_k_aug_interface.py +++ b/pyomo/contrib/sensitivity_toolbox/tests/test_k_aug_interface.py @@ -20,7 +20,6 @@ # This software is distributed under the 3-clause BSD License. # ____________________________________________________________________________ -""" """ import os import pyomo.common.unittest as unittest from io import StringIO From 3a0cf092a6f7aa5464a97af5efdf155afa38925d Mon Sep 17 00:00:00 2001 From: John Siirola Date: Wed, 29 Jan 2025 11:32:57 -0700 Subject: [PATCH 8/8] NFC: fix typo Co-authored-by: Bethany Nicholson --- pyomo/contrib/viewer/tests/test_qt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyomo/contrib/viewer/tests/test_qt.py b/pyomo/contrib/viewer/tests/test_qt.py index 2ef862b087c..ffa5f4d52b5 100644 --- a/pyomo/contrib/viewer/tests/test_qt.py +++ b/pyomo/contrib/viewer/tests/test_qt.py @@ -24,7 +24,7 @@ UI Tests """ # The pytest-qt plugin can generate exceptions / core dumps when it is -# run in a terminal (without an axtive X11 screen). Setting the +# run in a terminal (without an active X11 screen). Setting the # QT_QPA_PLATFORM environment variable *before* initializing Qt can work # around this error (see https://stackoverflow.com/a/74719383): import os