Skip to content

Commit

Permalink
Merge pull request #1695 from swryan/work
Browse files Browse the repository at this point in the history
Change calls to super to use Python3 syntax.
  • Loading branch information
swryan committed Sep 23, 2020
2 parents e18df7c + e93aa5a commit 3236bfa
Show file tree
Hide file tree
Showing 133 changed files with 429 additions and 428 deletions.
2 changes: 1 addition & 1 deletion openmdao/approximation_schemes/complex_step.py
Expand Up @@ -37,7 +37,7 @@ def __init__(self):
"""
Initialize the ApproximationScheme.
"""
super(ComplexStep, self).__init__()
super().__init__()

# Only used when nested under complex step.
self._fd = None
Expand Down
2 changes: 1 addition & 1 deletion openmdao/approximation_schemes/finite_difference.py
Expand Up @@ -90,7 +90,7 @@ def __init__(self):
"""
Initialize the ApproximationScheme.
"""
super(FiniteDifference, self).__init__()
super().__init__()
self._starting_ins = self._starting_outs = self._results_tmp = None

def add_approximation(self, abs_key, system, kwargs, vector=None):
Expand Down
4 changes: 2 additions & 2 deletions openmdao/components/add_subtract_comp.py
Expand Up @@ -69,7 +69,7 @@ def __init__(self, output_name=None, input_names=None, vec_size=1, length=1,
(same as add_output method for ExplicitComponent)
Examples include units (str or None), desc (str)
"""
super(AddSubtractComp, self).__init__()
super().__init__()

# Add systems is used to store those systems provided upon initialization
self._equations = []
Expand Down Expand Up @@ -181,7 +181,7 @@ def add_equation(self, output_name, input_names, vec_size=1, length=1, val=1.0,
else:
shape = (vec_size, length)

super(AddSubtractComp, self).add_output(output_name, val, shape=shape, **kwargs)
super().add_output(output_name, val, shape=shape, **kwargs)

self._equations.append((output_name, input_names, vec_size, length, val,
scaling_factors, kwargs))
Expand Down
4 changes: 2 additions & 2 deletions openmdao/components/balance_comp.py
Expand Up @@ -132,10 +132,10 @@ def __init__(self, name=None, eq_units=None, lhs_name=None, rhs_name=None, rhs_v
(see `add_output` method).
"""
if 'guess_func' in kwargs:
super(BalanceComp, self).__init__(guess_func=kwargs['guess_func'])
super().__init__(guess_func=kwargs['guess_func'])
kwargs.pop('guess_func')
else:
super(BalanceComp, self).__init__()
super().__init__()

self._state_vars = {}

Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/cross_product_comp.py
Expand Up @@ -40,7 +40,7 @@ def __init__(self, **kwargs):
**kwargs : dict of keyword arguments
Keyword arguments that will be mapped into the Component options.
"""
super(CrossProductComp, self).__init__(**kwargs)
super().__init__(**kwargs)

self._products = []

Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/demux_comp.py
Expand Up @@ -27,7 +27,7 @@ def __init__(self, **kwargs):
**kwargs : dict
Arguments to be passed to the component initialization method.
"""
super(DemuxComp, self).__init__(**kwargs)
super().__init__(**kwargs)

self._vars = {}
self._output_names = {}
Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/dot_product_comp.py
Expand Up @@ -34,7 +34,7 @@ def __init__(self, **kwargs):
**kwargs : dict of keyword arguments
Keyword arguments that will be mapped into the Component options.
"""
super(DotProductComp, self).__init__(**kwargs)
super().__init__(**kwargs)

self._products = []

Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/eq_constraint_comp.py
Expand Up @@ -96,7 +96,7 @@ def __init__(self, name=None, eq_units=None, lhs_name=None, rhs_name=None, rhs_v
Additional arguments to be passed for the creation of the output variable.
(see `add_output` method).
"""
super(EQConstraintComp, self).__init__()
super().__init__()
self._output_vars = {}
if name is not None:
self.add_eq_output(name, eq_units, lhs_name, rhs_name, rhs_val,
Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/exec_comp.py
Expand Up @@ -209,7 +209,7 @@ def __init__(self, exprs=[], **kwargs):
if name in kwargs:
options[name] = kwargs.pop(name)

super(ExecComp, self).__init__(**options)
super().__init__(**options)

# if complex step is used for derivatives, this is the stepsize
self.complex_stepsize = 1.e-40
Expand Down
8 changes: 4 additions & 4 deletions openmdao/components/external_code_comp.py
Expand Up @@ -263,7 +263,7 @@ def __init__(self, **kwargs):
Keyword arguments that will be mapped into the Component options.
"""
self._external_code_runner = ExternalCodeDelegate(self)
super(ExternalCodeComp, self).__init__(**kwargs)
super().__init__(**kwargs)

self.stdin = DEV_NULL
self.stdout = None
Expand All @@ -278,7 +278,7 @@ def _declare_options(self):
Options are declared here because this class is intended to be subclassed by
the end user. The `initialize` method is left available for user-defined options.
"""
super(ExternalCodeComp, self)._declare_options()
super()._declare_options()
self._external_code_runner.declare_options()

def check_config(self, logger):
Expand Down Expand Up @@ -340,7 +340,7 @@ def __init__(self, **kwargs):
Keyword arguments that will be mapped into the Component options.
"""
self._external_code_runner = ExternalCodeDelegate(self)
super(ExternalCodeImplicitComp, self).__init__(**kwargs)
super().__init__(**kwargs)

self.stdin = DEV_NULL
self.stdout = None
Expand All @@ -355,7 +355,7 @@ def _declare_options(self):
Options are declared here because this class is intended to be subclassed by
the end user. The `initialize` method is left available for user-defined options.
"""
super(ExternalCodeImplicitComp, self)._declare_options()
super()._declare_options()
self._external_code_runner.declare_options()

# ImplicitComponent has two separate commands to run.
Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/interp_util/interp_akima.py
Expand Up @@ -95,7 +95,7 @@ def __init__(self, grid, values, interp, **kwargs):
**kwargs : dict
Interpolator-specific options to pass onward.
"""
super(InterpAkima, self).__init__(grid, values, interp, **kwargs)
super().__init__(grid, values, interp, **kwargs)
self.k = 4
self._name = 'akima'

Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/interp_util/interp_bsplines.py
Expand Up @@ -45,7 +45,7 @@ def __init__(self, grid, values, interp=None, **kwargs):
**kwargs : dict
Interpolator-specific options to pass onward.
"""
super(InterpBSplines, self).__init__(grid, values, interp, **kwargs)
super().__init__(grid, values, interp, **kwargs)

self._vectorized = True
self.k = self.options['order'] + 1
Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/interp_util/interp_cubic.py
Expand Up @@ -37,7 +37,7 @@ def __init__(self, grid, values, interp, **kwargs):
**kwargs : dict
Interpolator-specific options to pass onward.
"""
super(InterpCubic, self).__init__(grid, values, interp)
super().__init__(grid, values, interp)
self.second_derivs = None
self.k = 4
self._name = 'cubic'
Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/interp_util/interp_lagrange2.py
Expand Up @@ -28,7 +28,7 @@ def __init__(self, grid, values, interp, **kwargs):
**kwargs : dict
Interpolator-specific options to pass onward.
"""
super(InterpLagrange2, self).__init__(grid, values, interp, **kwargs)
super().__init__(grid, values, interp, **kwargs)
self.k = 3
self._name = 'lagrange2'

Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/interp_util/interp_lagrange3.py
Expand Up @@ -28,7 +28,7 @@ def __init__(self, grid, values, interp, **kwargs):
**kwargs : dict
Interpolator-specific options to pass onward.
"""
super(InterpLagrange3, self).__init__(grid, values, interp, **kwargs)
super().__init__(grid, values, interp, **kwargs)
self.k = 4
self._name = 'lagrange3'

Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/interp_util/interp_slinear.py
Expand Up @@ -28,7 +28,7 @@ def __init__(self, grid, values, interp, **kwargs):
**kwargs : dict
Interpolator-specific options to pass onward.
"""
super(InterpLinear, self).__init__(grid, values, interp, **kwargs)
super().__init__(grid, values, interp, **kwargs)
self.k = 2
self._name = 'slinear'

Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/interp_util/outofbounds_error.py
Expand Up @@ -34,7 +34,7 @@ def __init__(self, message, idx, value, lower, upper):
upper : double
upper bounds of the variable that is out of bounds.
"""
super(OutOfBoundsError, self).__init__(message)
super().__init__(message)
self.idx = idx
self.value = value
self.lower = lower
Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/ks_comp.py
Expand Up @@ -146,7 +146,7 @@ def __init__(self, **kwargs):
**kwargs : dict of keyword arguments
Keyword arguments that will be mapped into the Component options.
"""
super(KSComp, self).__init__(**kwargs)
super().__init__(**kwargs)

self.cite = CITATIONS

Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/linear_system_comp.py
Expand Up @@ -29,7 +29,7 @@ def __init__(self, **kwargs):
**kwargs : dict of keyword arguments
Keyword arguments that will be mapped into the Component options.
"""
super(LinearSystemComp, self).__init__(**kwargs)
super().__init__(**kwargs)
self._lup = None

def initialize(self):
Expand Down
2 changes: 1 addition & 1 deletion openmdao/components/matrix_vector_product_comp.py
Expand Up @@ -44,7 +44,7 @@ def __init__(self, **kwargs):
**kwargs : dict of keyword arguments
Keyword arguments that will be mapped into the Component options.
"""
super(MatrixVectorProductComp, self).__init__(**kwargs)
super().__init__(**kwargs)

self._products = []

Expand Down
25 changes: 11 additions & 14 deletions openmdao/components/meta_model_structured_comp.py
Expand Up @@ -48,7 +48,7 @@ def __init__(self, **kwargs):
**kwargs : dict of keyword arguments
Keyword arguments that will be mapped into the Component options.
"""
super(MetaModelStructuredComp, self).__init__(**kwargs)
super().__init__(**kwargs)

self.pnames = []
self.inputs = []
Expand Down Expand Up @@ -95,7 +95,7 @@ def add_input(self, name, val=1.0, training_data=None, **kwargs):
msg = "{}: Input {} must either be scalar, or of length equal to vec_size."
raise ValueError(msg.format(self.msginfo, name))

super(MetaModelStructuredComp, self).add_input(name, val * np.ones(n), **kwargs)
super().add_input(name, val * np.ones(n), **kwargs)

self.pnames.append(name)
self.inputs.append(np.asarray(training_data))
Expand Down Expand Up @@ -124,13 +124,12 @@ def add_output(self, name, val=1.0, training_data=None, **kwargs):
msg = "{}: Output {} must either be scalar, or of length equal to vec_size."
raise ValueError(msg.format(self.msginfo, name))

super(MetaModelStructuredComp, self).add_output(name, val * np.ones(n), **kwargs)
super().add_output(name, val * np.ones(n), **kwargs)

self.training_outputs[name] = training_data

if self.options['training_data_gradients']:
super(MetaModelStructuredComp, self).add_input("%s_train" % name,
val=training_data, **kwargs)
super().add_input("%s_train" % name, val=training_data, **kwargs)

def _setup_var_data(self):
"""
Expand All @@ -149,15 +148,15 @@ def _setup_var_data(self):
if self.options['training_data_gradients']:
self.grad_shape = tuple([self.options['vec_size']] + [i.size for i in self.inputs])

super(MetaModelStructuredComp, self)._setup_var_data()
super()._setup_var_data()

def _setup_partials(self):
"""
Process all partials and approximations that the user declared.
Metamodel needs to declare its partials after inputs and outputs are known.
"""
super(MetaModelStructuredComp, self)._setup_partials()
super()._setup_partials()
arange = np.arange(self.options['vec_size'])
pnames = tuple(self.pnames)
dct = {
Expand Down Expand Up @@ -198,17 +197,15 @@ def compute(self, inputs, outputs):

except OutOfBoundsError as err:
varname_causing_error = '.'.join((self.pathname, self.pnames[err.idx]))
errmsg = "{}: Error interpolating output '{}' because input '{}' " \
"was out of bounds ('{}', '{}') with " \
"value '{}'".format(self.msginfo, out_name, varname_causing_error,
err.lower, err.upper, err.value)
errmsg = (f"{self.msginfo}: Error interpolating output '{out_name}' "
f"because input '{varname_causing_error}' was out of bounds "
f"('{ err.lower}', '{err.upper}') with value '{err.value}'")
raise AnalysisError(errmsg, inspect.getframeinfo(inspect.currentframe()),
self.msginfo)

except ValueError as err:
raise ValueError("{}: Error interpolating output '{}':\n{}".format(self.msginfo,
out_name,
str(err)))
raise ValueError(f"{self.msginfo}: Error interpolating output '{out_name}':\n"
f"{str(err)}")
outputs[out_name] = val

def compute_partials(self, inputs, partials):
Expand Down
16 changes: 8 additions & 8 deletions openmdao/components/meta_model_unstructured_comp.py
Expand Up @@ -53,7 +53,7 @@ def __init__(self, **kwargs):
**kwargs : dict of keyword arguments
Keyword arguments that will be mapped into the Component options.
"""
super(MetaModelUnStructuredComp, self).__init__(**kwargs)
super().__init__(**kwargs)

# keep list of inputs and outputs that are not the training vars
self._surrogate_input_names = []
Expand Down Expand Up @@ -95,7 +95,7 @@ def _setup_procs(self, pathname, comm, mode, prob_meta):
self._surrogate_output_names.extend(self._static_surrogate_output_names)
self._input_size = self._static_input_size

super(MetaModelUnStructuredComp, self)._setup_procs(pathname, comm, mode, prob_meta)
super()._setup_procs(pathname, comm, mode, prob_meta)

def initialize(self):
"""
Expand Down Expand Up @@ -128,7 +128,7 @@ def add_input(self, name, val=1.0, training_data=None, **kwargs):
dict
metadata for added variable
"""
metadata = super(MetaModelUnStructuredComp, self).add_input(name, val, **kwargs)
metadata = super().add_input(name, val, **kwargs)
vec_size = self.options['vec_size']

if vec_size > 1:
Expand Down Expand Up @@ -177,7 +177,7 @@ def add_output(self, name, val=1.0, training_data=None, surrogate=None, **kwargs
dict
metadata for added variable
"""
metadata = super(MetaModelUnStructuredComp, self).add_output(name, val, **kwargs)
metadata = super().add_output(name, val, **kwargs)
vec_size = self.options['vec_size']

if vec_size > 1:
Expand Down Expand Up @@ -235,15 +235,15 @@ def _setup_var_data(self):
# training will occur on first execution after setup
self.train = True

super(MetaModelUnStructuredComp, self)._setup_var_data()
super()._setup_var_data()

def _setup_partials(self):
"""
Process all partials and approximations that the user declared.
Metamodel needs to declare its partials after inputs and outputs are known.
"""
super(MetaModelUnStructuredComp, self)._setup_partials()
super()._setup_partials()

vec_size = self.options['vec_size']
if vec_size > 1:
Expand Down Expand Up @@ -502,8 +502,8 @@ def declare_partials(self, of, wrt, dependent=True, rows=None, cols=None, val=No
"""
if method == 'cs':
raise ValueError('Complex step has not been tested for MetaModelUnStructuredComp')
super(MetaModelUnStructuredComp, self).declare_partials(of, wrt, dependent, rows, cols,
val, method, step, form, step_calc)
super().declare_partials(of, wrt, dependent, rows, cols,
val, method, step, form, step_calc)

def compute_partials(self, inputs, partials):
"""
Expand Down

0 comments on commit 3236bfa

Please sign in to comment.