Skip to content

Commit

Permalink
Basic linting
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniogi committed Sep 29, 2024
1 parent 4bb612a commit 2117739
Show file tree
Hide file tree
Showing 12 changed files with 360 additions and 423 deletions.
57 changes: 25 additions & 32 deletions src/Parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
# limitations under the License. #
#############################################################################

__author__ = ' AUTHORS: Antonio Gomez ([email protected])'

import Utils as u

__author__ = ' AUTHORS: Antonio Gomez ([email protected])'
__version__ = ' REVISION: 1.0 - 15-01-2014'

"""
Expand All @@ -28,14 +28,9 @@
Version 1.0 (15-01-2014): Fist stable version.
"""

import Utils as u


class Parameter(object):
"""
This class represents a parameter of the problem that will be used
during the optimization (a chromosome in Genetic Algorithms).
"""
#This class represents a parameter of the problem that will be used
#during the optimization (a chromosome in Genetic Algorithms).
class Parameter():

def __init__(self):
self.__value = None
Expand All @@ -48,21 +43,20 @@ def __init__(self):

def set_value(self, value):
try:
if (self.__type == "string"):
if self.__type == "string":
self.__value = value
elif (self.__type == "double") or (self.__type == "float"):
elif self.__type in ('double', 'float'):
self.__value = float(value)
elif (self.__type == "bool"):
self.__value = ((value == "T") or (value == "True") or
(value == "TRUE"))
elif self.__type == "bool":
self.__value = value in ('TRUE', 'True', 'true', 'T', 't', '1')
else:
self.__value = int(round(value))
except Exception as e:
u.logger.error("Parameter. Error when setting value of " +
"parameter: " + str(e))

def get_index(self):
return (self.__index)
return self.__index

def set_index(self, index):
try:
Expand All @@ -75,7 +69,7 @@ def set_name(self, name):
self.__name = str(name)

def get_name(self):
return (self.__name)
return self.__name

def set_type(self, type_):
self.__type = type_
Expand All @@ -84,24 +78,23 @@ def get_type(self):
return self.__type

def get_value(self):
if (self.__type == "double" or self.__type == "float"):
if self.__type in ('double', 'float'):
return float(self.__value)
if (self.__type == "int"):
if self.__type == "int":
return int(self.__value)
if (self.__type == "bool"):
if (self.__value == "T") or (self.__value == "True"):
if self.__type == "bool":
if self.__value in ('TRUE', 'True', 'true', 'T', 't', '1'):
return True
else:
return False
return False
return self.__value

def set_min_value(self, min_value):
try:
if (self.__type == "string"):
if self.__type == "string":
self.__min_value = ""
elif (self.__type == "double"):
elif self.__type == "double":
self.__min_value = float(min_value)
elif (self.__type == "bool"):
elif self.__type == "bool":
self.__min_value = False
else:
self.__min_value = int(min_value)
Expand All @@ -110,15 +103,15 @@ def set_min_value(self, min_value):
"parameter: " + str(e))

def get_min_value(self):
return (self.__min_value)
return self.__min_value

def set_max_value(self, max_value):
try:
if (self.__type == "string"):
if self.__type == "string":
self.__max_value = ""
elif (self.__type == "double"):
elif self.__type == "double":
self.__max_value = float(max_value)
elif (self.__type == "bool"):
elif self.__type == "bool":
self.__max_value = True
else:
self.__max_value = int(max_value)
Expand All @@ -130,10 +123,10 @@ def get_max_value(self):
return self.__max_value

def __getitem__(self, item):
return (self.__index)
return self.__index

def set_gap(self, gap):
self.__gap = float(gap)

def get_gap(self):
return (self.__gap)
return self.__gap
38 changes: 16 additions & 22 deletions src/ParameterVMEC.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
# limitations under the License. #
#############################################################################

__author__ = ' AUTHORS: Antonio Gomez ([email protected])'

from Parameter import Parameter
import Utils as u

__author__ = ' AUTHORS: Antonio Gomez ([email protected])'

__version__ = ' REVISION: 1.0 - 15-01-2014'

Expand All @@ -28,10 +31,6 @@
Version 1.0 (15-01-2014): Fist stable version.
"""

from Parameter import Parameter
import Utils as u


class ParameterVMEC(Parameter):
"""
Extension of the Parameter class. This class adds some extra attribute
Expand All @@ -49,23 +48,23 @@ def __init__(self):

def set_x_index(self, index):
try:
if (index is not None):
if index is not None:
self.__x_index = int(index)
except:
except ValueError:
pass

def set_y_index(self, index):
try:
if (index is not None):
if index is not None:
self.__y_index = int(index)
except:
except ValueError:
pass

def set_display(self, display):
self.__display = (str(display) == "True")
self.__display = str(display) == "True"

def set_fixed(self, fixed):
self.__fixed = (str(fixed) == "True")
self.__fixed = str(fixed) == "True"

def get_display(self):
return self.__display
Expand All @@ -74,10 +73,9 @@ def get_fixed(self):
return self.__fixed

def to_be_modified(self):
if (self.__fixed == False) and (self.__display == True):
if self.__display and not self.__fixed:
return True
else:
return False
return False

def get_x_index(self):
return self.__x_index
Expand All @@ -86,19 +84,15 @@ def get_y_index(self):
return self.__y_index

def print_value(self):
if (self.__type == "bool"):
if (self.__value):
print (str(self.__name) + ' = TRUE')
if self.__type == "bool":
if self.__value:
u.logger.info(str(self.__name) + ' = TRUE')
else:
print (str(self.__name) + ' = FALSE')
u.logger.info(str(self.__name) + ' = FALSE')
else:
print (str(self.__name) + ' = ' + str(self.__value))
u.logger.info(str(self.__name) + ' = ' + str(self.__value))

def get_value_and_index(self):
if (str(self.__type) == "float") or (str(self.__type) == "double"):
if str(self.__type) in ["float", "double"]:
return str("%.6E" % float(self.__value))
else:
return str(self.__value)
return str(self.__value)
2 changes: 1 addition & 1 deletion src/ProblemBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ProblemBase(object):
def __init__(self):
return

def solve(self):
def solve(self, solution):
raise NotImplementedError("Abstract problem")

def extractSolution(self):
Expand Down
39 changes: 14 additions & 25 deletions src/ProblemFusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
# limitations under the License. #
#############################################################################

import sys
from ProblemBase import ProblemBase
from VMECProcess import VMECProcess
import Utils as u

__author__ = ' AUTHORS: Antonio Gomez ([email protected])'


Expand All @@ -26,9 +31,7 @@
HISTORY
Version 0.1 (12-04-2013): Creation of the file.
Version 1.0 (15-01-2014): Fist stable version.
"""
"""
Objects of this class will represent an instance of the problem we want to
solve. In the case of fusion, it contains the information regarding one
stellarator's configuration.
Expand All @@ -37,11 +40,6 @@
(i.e. call VMEC or any other code)
"""

from ProblemBase import ProblemBase
from VMECProcess import VMECProcess
import Utils as u
import sys


class ProblemFusion (ProblemBase):

Expand All @@ -50,38 +48,29 @@ def __init__(self):
ProblemBase.__init__(self)
self.__vmec = VMECProcess(u.cfile)
except Exception as e:
print("ProblemFusion " + str(sys.exc_traceback.tb_lineno) +
" " + str(e))
return

"""
Creates a input.tj input file for vmec
"""
u.logger.error("ProblemFusion " + sys.exception().exc.__traceback__.tb_lineno +
" " + str(e))

#Creates a input.tj input file for vmec
def create_input_file(self, solution):
try:
if (not self.__vmec.create_input_file(solution)):
if not self.__vmec.create_input_file(solution):
return False
except Exception as e:
u.logger.error("ProblemFusion, when creating input file: " +
str(e))
return False
return True

"""
Main method responsible for calling vmec and all of the other
applications required based on the configuration specified by the user
"""

#Main method responsible for calling vmec and all of the other
#applications required based on the configuration specified by the user
def execute_configuration(self):
return (self.__vmec.execute_configuration())
return self.__vmec.execute_configuration()

def extractSolution(self):
u.logger.debug("Extract solution fusion")
"""
This function actually only needs to send back the values we need
"""
return self.__beta, self.__bgradbval
#This function actually only needs to send back the values we need
return self.__vmec.get_beta(), self.__vmec.get_bgradbval()

def solve(self, solution):
self.create_input_file(solution)
Expand Down
Loading

0 comments on commit 2117739

Please sign in to comment.