Repository: Pyomo/pyomo

Issue:
debug_vars.log
When contrib/trustregion/plugins.py is imported (i.e., `import pyomo.environ`), it is leaving around a file named "debug_vars.log". I'm finding these all over my project directories now. We should probably fix this before the release.


Discussion:

Resolving patch:
diff --git a/pyomo/contrib/trustregion/PyomoInterface.py b/pyomo/contrib/trustregion/PyomoInterface.py
--- a/pyomo/contrib/trustregion/PyomoInterface.py
+++ b/pyomo/contrib/trustregion/PyomoInterface.py
@@ -82,7 +82,7 @@ def visit(self, node, values):
         self.trf.exfn_xvars.append(new_args)
         return _y
 
-class PyomoInterface:
+class PyomoInterface(object):
     '''
     Initialize with a pyomo model m.
     This is used in TRF.py, same requirements for m apply
@@ -98,15 +98,14 @@ class PyomoInterface:
 
     '''
 
-    solver = 'ipopt'
-    solver_io = 'nl'
     stream_solver = False # True prints solver output to screen
     keepfiles = False  # True prints intermediate file names (.nl,.sol,...)
     countDx = -1
     romtype = ROMType.linear
 
-    def __init__(self, m, eflist):
+    def __init__(self, m, eflist, config):
 
+        self.config = config
         self.model = m;
         self.TRF = self.transformForTrustRegion(self.model,eflist)
 
@@ -413,9 +412,8 @@ def activateCompCheckObjective(self, x0, z0, rom_params, penalty):
 
     def solveModel(self, x, y, z):
         model = self.model
-        opt = SolverFactory(self.solver, solver_io=self.solver_io)
-        opt.options['halt_on_ampl_error'] = 'yes'
-        opt.options['max_iter'] = 5000
+        opt = SolverFactory(self.config.solver)
+        opt.options.update(self.config.solver_options)
 
         results = opt.solve(
             model, keepfiles=self.keepfiles, tee=self.stream_solver)
@@ -542,9 +540,10 @@ def linConMaker(l, i):
         gfnorm = sqrt(sum(x[1]**2 for x in g))
 
 
-        opt = SolverFactory(self.solver, solver_io=self.solver_io)
-        opt.options['halt_on_ampl_error'] = 'yes'
-        opt.options['max_iter'] = 5000
+        opt = SolverFactory(self.config.solver)
+        opt.options.update(self.config.solver_options)
+        #opt.options['halt_on_ampl_error'] = 'yes'
+        #opt.options['max_iter'] = 5000
         results = opt.solve(
             l, keepfiles=self.keepfiles, tee=self.stream_solver)
 
diff --git a/pyomo/contrib/trustregion/TRF.py b/pyomo/contrib/trustregion/TRF.py
--- a/pyomo/contrib/trustregion/TRF.py
+++ b/pyomo/contrib/trustregion/TRF.py
@@ -32,7 +32,7 @@ def TRF(m, eflist, config):
 
     logger = Logger()
     filteR = Filter()
-    problem = PyomoInterface(m, eflist)
+    problem = PyomoInterface(m, eflist, config)
     x, y, z = problem.getInitialValue()
 
     iteration = -1
diff --git a/pyomo/contrib/trustregion/plugins.py b/pyomo/contrib/trustregion/plugins.py
--- a/pyomo/contrib/trustregion/plugins.py
+++ b/pyomo/contrib/trustregion/plugins.py
@@ -15,9 +15,9 @@
 from pyomo.contrib.trustregion.readgjh import readgjh
 
 logger = logging.getLogger('pyomo.contrib.trustregion')
-fh = logging.FileHandler('debug_vars.log')
-logger.setLevel(logging.DEBUG)
-logger.addHandler(fh)
+#fh = logging.FileHandler('debug_vars.log')
+#logger.setLevel(logging.DEBUG)
+#logger.addHandler(fh)
 
 def load():
     pass
@@ -46,6 +46,11 @@ class TrustRegionSolver(OptSolver):
         description='solver to use, defaults to ipopt',
         doc = ''))
 
+    CONFIG.declare('solver_options', ConfigBlock(
+        implicit=True,
+        description='options to pass to the subproblem solver',
+        doc = ''))
+
     # Initialize trust radius
     CONFIG.declare('trust radius', ConfigValue(
         default = 1.0,
@@ -237,13 +242,13 @@ class TrustRegionSolver(OptSolver):
     def __init__(self, **kwds):
         # set persistent config options
         tmp_kwds = {'type':kwds.pop('type','trustregion')}
-        self.config = self.CONFIG(kwds)
+        self.config = self.CONFIG(kwds, preserve_implicit=True)
 
         #
         # Call base class constructor
         #
  
-        tmp_kwds['solver'] = 'ipopt'
+        tmp_kwds['solver'] = self.config.solver
         OptSolver.__init__(self, **tmp_kwds)
 
 
@@ -262,7 +267,7 @@ def version(self):
 
     def solve(self, model, eflist, **kwds):
         # set customized config parameters
-        self._local_config = self.config(kwds)
+        self._local_config = self.config(kwds, preserve_implicit=True)
 
         # first store all data we will need to change in original model as a tuple
         # [0]=Var component, [1]=external function list, [2]=config block


Test patch:
diff --git a/pyomo/contrib/trustregion/tests/TestPyomoInterface.py b/pyomo/contrib/trustregion/tests/TestPyomoInterface.py
--- a/pyomo/contrib/trustregion/tests/TestPyomoInterface.py
+++ b/pyomo/contrib/trustregion/tests/TestPyomoInterface.py
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 
 import pyutilib.th as unittest
+from pyutilib.misc.config import ConfigBlock
 
 from pyomo.core.expr.current import identify_variables
 from pyomo.environ import *
@@ -39,7 +40,7 @@ def blackbox(a,b):
         bb = ExternalFunction(blackbox)
         m.eflist = [bb]
         m.c1 = Constraint(expr=m.x[0] * m.z[0]**2 + bb(m.x[0],m.x[1]) == 2*sqrt(2.0))
-        pI = PyomoInterface(m, [bb])
+        pI = PyomoInterface(m, [bb], ConfigBlock())
         self.assertEqual(pI.lx,2)
         self.assertEqual(pI.ly,1)
         self.assertEqual(pI.lz,3)
@@ -57,7 +58,7 @@ def blackbox(a):
         bb = ExternalFunction(blackbox)
         m.eflist = [bb]
         m.c1 = Constraint(expr=m.x[0] * m.z[0]**2 + bb(m.x[0]-m.x[1]) == 2*sqrt(2.0))
-        pI = PyomoInterface(m, [bb])
+        pI = PyomoInterface(m, [bb], ConfigBlock())
         self.assertEqual(pI.lx,1)
         self.assertEqual(pI.ly,1)
         self.assertEqual(pI.lz,5)
@@ -78,7 +79,7 @@ def blackbox(a,b):
         m.eflist = [bb]
         m.c1 = Constraint(expr=m.x[0] * m.z[0]**2 + bb(m.x[0], m.x[1]) == 2*sqrt(2.0))
         m.c3 = Constraint(expr=m.x[0] * m.z[0]**2 + bb(m.x[0], m.z[1]) == 2*sqrt(2.0))
-        pI = PyomoInterface(m, [bb])
+        pI = PyomoInterface(m, [bb], ConfigBlock())
         self.assertEqual(pI.lx,3)
         self.assertEqual(pI.ly,2)
         self.assertEqual(pI.lz,2)
@@ -99,7 +100,7 @@ def blackbox(a,b):
         m.eflist = [bb]
         m.c1 = Constraint(expr=m.x[0] * m.z[0]**2 + bb(m.x[0], m.x[1]) == 2*sqrt(2.0))
         m.c3 = Constraint(expr=m.x[0] * m.z[0]**2 + bb(m.x[0], m.z[1]) == 2*sqrt(2.0))
-        pI = PyomoInterface(m, [bb])
+        pI = PyomoInterface(m, [bb], ConfigBlock())
         self.assertEqual(pI.lx,3)
         self.assertEqual(pI.ly,2)
         self.assertEqual(pI.lz,2)
diff --git a/pyomo/contrib/trustregion/tests/TestTRConfig.py b/pyomo/contrib/trustregion/tests/TestTRConfig.py
--- a/pyomo/contrib/trustregion/tests/TestTRConfig.py
+++ b/pyomo/contrib/trustregion/tests/TestTRConfig.py
@@ -17,6 +17,7 @@
     numpy_available = False
 
 
+@unittest.skipIf(not SolverFactory('gjh').available(False), "The GJH solver is not available")
 @unittest.skipIf(not numpy_available, "Cannot test the trustregion solver without numpy")
 class TestTrustRegionConfigBlock(unittest.TestCase):
     def setUp(self):
@@ -125,7 +126,7 @@ def test_initialize_with_kwdval(self):
         self.assertEqual(self.optTRF._local_config.trust_radius, 3.0)
         
 
-    def initialize_with_kwdval_solve_with_new_kwdval(self):
+    def test_initialize_with_kwdval_solve_with_new_kwdval(self):
 
         # Initialized with 3.0
         self.optTRF = SolverFactory('trustregion', trust_radius=3.0)