Skip to content

Commit d844e3c

Browse files
EslickEslick
Eslick
authored and
Eslick
committed
Run black on changed files
1 parent e550079 commit d844e3c

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

Diff for: pyomo/solvers/plugins/solvers/ASL.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727

2828
import logging
2929

30-
logger = logging.getLogger('pyomo.solvers')
30+
logger = logging.getLogger("pyomo.solvers")
3131

3232

3333
@SolverFactory.register(
34-
'asl', doc='Interface for solvers using the AMPL Solver Library'
34+
"asl", doc="Interface for solvers using the AMPL Solver Library"
3535
)
3636
class ASL(SystemCallSolver):
3737
"""A generic optimizer that uses the AMPL Solver Library to interface with applications."""
@@ -40,7 +40,7 @@ def __init__(self, **kwds):
4040
#
4141
# Call base constructor
4242
#
43-
if not 'type' in kwds:
43+
if not "type" in kwds:
4444
kwds["type"] = "asl"
4545
SystemCallSolver.__init__(self, **kwds)
4646
self._metasolver = True
@@ -93,7 +93,7 @@ def _get_version(self):
9393
"""
9494
solver_exec = self.executable()
9595
if solver_exec is None:
96-
return _extract_version('')
96+
return _extract_version("")
9797
try:
9898
results = subprocess.run(
9999
[solver_exec, "-v"],
@@ -105,8 +105,8 @@ def _get_version(self):
105105
ver = _extract_version(results.stdout)
106106
if ver is None:
107107
# Some ASL solvers do not export a version number
108-
if results.stdout.strip().split()[-1].startswith('ASL('):
109-
return '0.0.0'
108+
if results.stdout.strip().split()[-1].startswith("ASL("):
109+
return "0.0.0"
110110
return ver
111111
except OSError:
112112
pass
@@ -139,9 +139,9 @@ def create_command_line(self, executable, problem_files):
139139
"The 'soln_file' keyword will be ignored for solver=" + self.type
140140
)
141141
fname = problem_files[0]
142-
if '.' in fname:
143-
tmp = fname.split('.')
144-
fname = '.'.join(tmp[:-1])
142+
if "." in fname:
143+
tmp = fname.split(".")
144+
fname = ".".join(tmp[:-1])
145145
self._soln_file = fname + ".sol"
146146

147147
#
@@ -158,15 +158,15 @@ def create_command_line(self, executable, problem_files):
158158
# Pyomo/Pyomo) with any user-specified external function
159159
# libraries
160160
#
161-
if 'PYOMO_AMPLFUNC' in env:
162-
if 'AMPLFUNC' in env:
163-
for line in env['PYOMO_AMPLFUNC'].split('\n'):
164-
if line not in env['AMPLFUNC']:
165-
env['AMPLFUNC'] += "\n" + line
161+
if "PYOMO_AMPLFUNC" in env:
162+
if "AMPLFUNC" in env:
163+
for line in env["PYOMO_AMPLFUNC"].split("\n"):
164+
if line not in env["AMPLFUNC"]:
165+
env["AMPLFUNC"] += "\n" + line
166166
else:
167-
env['AMPLFUNC'] = env['PYOMO_AMPLFUNC']
167+
env["AMPLFUNC"] = env["PYOMO_AMPLFUNC"]
168168

169-
cmd = [executable, problem_files[0], '-AMPL']
169+
cmd = [executable, problem_files[0], "-AMPL"]
170170
if self._timer:
171171
cmd.insert(0, self._timer)
172172
#
@@ -181,12 +181,12 @@ def create_command_line(self, executable, problem_files):
181181
#
182182
opt = []
183183
for key in self.options:
184-
if key == 'solver':
184+
if key == "solver":
185185
continue
186-
if isinstance(self.options[key], str) and (' ' in self.options[key]):
187-
opt.append(key + "=\"" + str(self.options[key]) + "\"")
186+
if isinstance(self.options[key], str) and (" " in self.options[key]):
187+
opt.append(key + '="' + str(self.options[key]) + '"')
188188
cmd.append(str(key) + "=" + str(self.options[key]))
189-
elif key == 'subsolver':
189+
elif key == "subsolver":
190190
opt.append("solver=" + str(self.options[key]))
191191
cmd.append(str(key) + "=" + str(self.options[key]))
192192
else:
@@ -202,9 +202,9 @@ def create_command_line(self, executable, problem_files):
202202
def _presolve(self, *args, **kwds):
203203
if (not isinstance(args[0], str)) and (not isinstance(args[0], IBlock)):
204204
self._instance = args[0]
205-
xfrm = TransformationFactory('mpec.nl')
205+
xfrm = TransformationFactory("mpec.nl")
206206
xfrm.apply_to(self._instance)
207-
if len(self._instance._transformation_data['mpec.nl'].compl_cuids) == 0:
207+
if len(self._instance._transformation_data["mpec.nl"].compl_cuids) == 0:
208208
# There were no complementarity conditions
209209
# so we don't hold onto the instance
210210
self._instance = None
@@ -223,7 +223,7 @@ def _postsolve(self):
223223
if not self._instance is None:
224224
from pyomo.mpec import Complementarity
225225

226-
for cuid in self._instance._transformation_data['mpec.nl'].compl_cuids:
226+
for cuid in self._instance._transformation_data["mpec.nl"].compl_cuids:
227227
mpec = True
228228
cobj = cuid.find_component_on(self._instance)
229229
cobj.parent_block().reclassify_component_type(cobj, Complementarity)
@@ -232,7 +232,7 @@ def _postsolve(self):
232232
return SystemCallSolver._postsolve(self)
233233

234234

235-
@SolverFactory.register('_mock_asl')
235+
@SolverFactory.register("_mock_asl")
236236
class MockASL(ASL, MockMIP):
237237
"""A Mock ASL solver used for testing"""
238238

Diff for: pyomo/solvers/plugins/solvers/IPOPT.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323

2424
import logging
2525

26-
logger = logging.getLogger('pyomo.solvers')
26+
logger = logging.getLogger("pyomo.solvers")
2727

2828

29-
@SolverFactory.register('ipopt', doc='The Ipopt NLP solver')
29+
@SolverFactory.register("ipopt", doc="The Ipopt NLP solver")
3030
class IPOPT(SystemCallSolver):
3131
"""
3232
An interface to the Ipopt optimizer that uses the AMPL Solver Library.
@@ -76,7 +76,7 @@ def _get_version(self):
7676
"""
7777
solver_exec = self.executable()
7878
if solver_exec is None:
79-
return _extract_version('')
79+
return _extract_version("")
8080
results = subprocess.run(
8181
[solver_exec, "-v"],
8282
timeout=self._version_timeout,
@@ -97,10 +97,10 @@ def create_command_line(self, executable, problem_files):
9797
self._log_file = TempfileManager.create_tempfile(suffix="_ipopt.log")
9898

9999
fname = problem_files[0]
100-
if '.' in fname:
101-
tmp = fname.split('.')
100+
if "." in fname:
101+
tmp = fname.split(".")
102102
if len(tmp) > 2:
103-
fname = '.'.join(tmp[:-1])
103+
fname = ".".join(tmp[:-1])
104104
else:
105105
fname = tmp[0]
106106
self._soln_file = fname + ".sol"
@@ -119,32 +119,32 @@ def create_command_line(self, executable, problem_files):
119119
# Pyomo/Pyomo) with any user-specified external function
120120
# libraries
121121
#
122-
if 'PYOMO_AMPLFUNC' in env:
123-
if 'AMPLFUNC' in env:
124-
for line in env['PYOMO_AMPLFUNC'].split('\n'):
125-
if line not in env['AMPLFUNC']:
126-
env['AMPLFUNC'] += "\n" + line
122+
if "PYOMO_AMPLFUNC" in env:
123+
if "AMPLFUNC" in env:
124+
for line in env["PYOMO_AMPLFUNC"].split("\n"):
125+
if line not in env["AMPLFUNC"]:
126+
env["AMPLFUNC"] += "\n" + line
127127
else:
128-
env['AMPLFUNC'] = env['PYOMO_AMPLFUNC']
128+
env["AMPLFUNC"] = env["PYOMO_AMPLFUNC"]
129129

130-
cmd = [executable, problem_files[0], '-AMPL']
130+
cmd = [executable, problem_files[0], "-AMPL"]
131131
if self._timer:
132132
cmd.insert(0, self._timer)
133133

134134
env_opt = []
135135
of_opt = []
136136
ofn_option_used = False
137137
for key in self.options:
138-
if key == 'solver':
138+
if key == "solver":
139139
continue
140140
elif key.startswith("OF_"):
141141
assert len(key) > 3
142142
of_opt.append((key[3:], self.options[key]))
143143
else:
144144
if key == "option_file_name":
145145
ofn_option_used = True
146-
if isinstance(self.options[key], str) and ' ' in self.options[key]:
147-
env_opt.append(key + "=\"" + str(self.options[key]) + "\"")
146+
if isinstance(self.options[key], str) and " " in self.options[key]:
147+
env_opt.append(key + '="' + str(self.options[key]) + '"')
148148
cmd.append(str(key) + "=" + str(self.options[key]))
149149
else:
150150
env_opt.append(key + "=" + str(self.options[key]))
@@ -167,7 +167,7 @@ def create_command_line(self, executable, problem_files):
167167
# Now check if an 'ipopt.opt' file exists in the
168168
# current working directory. If so, we need to
169169
# make it clear that this file will be ignored.
170-
default_of_name = os.path.join(os.getcwd(), 'ipopt.opt')
170+
default_of_name = os.path.join(os.getcwd(), "ipopt.opt")
171171
if os.path.exists(default_of_name):
172172
logger.warning(
173173
"A file named '%s' exists in "
@@ -187,7 +187,7 @@ def create_command_line(self, executable, problem_files):
187187
# Now set the command-line option telling Ipopt
188188
# to use this file
189189
env_opt.append('option_file_name="' + str(options_filename) + '"')
190-
cmd.append('option_file_name=' + str(options_filename))
190+
cmd.append("option_file_name=" + str(options_filename))
191191

192192
envstr = "%s_options" % self.options.solver
193193
# Merge with any options coming in through the environment
@@ -206,6 +206,6 @@ def process_output(self, rc):
206206
with open(self._log_file) as f:
207207
for line in f:
208208
if "TOO_FEW_DEGREES_OF_FREEDOM" in line:
209-
res.solver.message = line.split(':')[2].strip()
209+
res.solver.message = line.split(":")[2].strip()
210210
assert "degrees of freedom" in res.solver.message
211211
return res

0 commit comments

Comments
 (0)