コード例 #1
0
class CC3DParameterScanResource(CC3DResource):
    def __init__(self):
        CC3DResource.__init__(self)
        self.resourceName = 'CC3DParameterScanResource'
        self.type = 'ParameterScan'
        self.basePath = ''

        self.parameterScanXMLElements = {}
        self.parameterScanFileToDataMap = {}  # {file name:dictionary of parameterScanData} parameterScanDataMap={hash:parameterScanData}
        # self.parameterScanDataMap = {}
        self.fileTypeForEditor = 'xml'
        self.parameterScanXMLHandler = None
        # self.parameterScanEditor=None

        self.psu = ParameterScanUtils()  # ParameterScanUtils is the class where all parsing and parameter scan data processing takes place

    def addParameterScanData(self, _file, _psd):
        print 'self.basePath=', self.basePath
        print '_file=', _file
        relativePath = findRelativePath(self.basePath,
                                        _file)  # relative path of the scanned simulation file w.r.t. project directory
        print 'relativePath=', relativePath
        self.psu.addParameterScanData(relativePath, _psd)

    def readParameterScanSpecs(self):
        self.psu.readParameterScanSpecs(self.path)

    def writeParameterScanSpecs(self):
        self.psu.writeParameterScanSpecs(self.path)
コード例 #2
0
class CC3DParameterScanResource(CC3DResource):
    def __init__(self):
        CC3DResource.__init__(self)
        self.resourceName = 'CC3DParameterScanResource'
        self.type = 'ParameterScan'
        self.basePath = ''

        self.parameterScanXMLElements = {}
        self.parameterScanFileToDataMap = {}  # {file name:dictionary of parameterScanData} parameterScanDataMap={hash:parameterScanData}
        # self.parameterScanDataMap = {}
        self.fileTypeForEditor = 'xml'
        self.parameterScanXMLHandler = None
        # self.parameterScanEditor=None

        self.psu = ParameterScanUtils()  # ParameterScanUtils is the class where all parsing and parameter scan data processing takes place

    def addParameterScanData(self, _file, _psd):
        print 'self.basePath=', self.basePath
        print '_file=', _file
        relativePath = findRelativePath(self.basePath,
                                        _file)  # relative path of the scanned simulation file w.r.t. project directory
        print 'relativePath=', relativePath
        self.psu.addParameterScanData(relativePath, _psd)

    def readParameterScanSpecs(self):
        self.psu.readParameterScanSpecs(self.path)

    def writeParameterScanSpecs(self):
        self.psu.writeParameterScanSpecs(self.path)
コード例 #3
0
def prepareParameterScan(_cc3dSimulationDataHandler):
    """This fcn returns True if preparation of the next PS run was succesfull or False otherwise - this will usually happen when parameter scan reaches max iteration . 
    """

    pScanFilePath = _cc3dSimulationDataHandler.cc3dSimulationData.parameterScanResource.path  # parameter scan file path
    cc3dProjectPath = _cc3dSimulationDataHandler.cc3dSimulationData.path
    cc3dProjectDir = _cc3dSimulationDataHandler.cc3dSimulationData.basePath

    # psu = _cc3dSimulationDataHandler.cc3dSimulationData.parameterScanResource.psu #parameter scan utils

    # checking if simulation file directory is writeable if not parameterscan cannot run properly - writeable simulation fiel directory is requirement for parameter scan
    if not os.access(cc3dProjectDir, os.W_OK):
        raise AssertionError(
            "parameter Scan Error: CC3D project directory:"
            + cc3dProjectDir
            + " has to be writeable. Please change permission on the directory of the .cc3d project"
        )
    # check if parameter scan file is writeable
    if not os.access(pScanFilePath, os.W_OK):
        raise AssertionError(
            "parameter Scan Error: Parameter Scan xml file :"
            + pScanFilePath
            + " has to be writeable. Please change permission on this file"
        )

    # We use separate ParameterScanUtils object to handle parameter scan
    from ParameterScanUtils import ParameterScanUtils

    psu = ParameterScanUtils()
    psu.readParameterScanSpecs(pScanFilePath)

    paramScanSpecsDirName = os.path.dirname(pScanFilePath)

    outputDir = (
        getRootOutputDir()
    )  # output dir is determined in a way that dpes not require PyQt4  and Configuration module

    customOutputPath = psu.prepareParameterScanOutputDirs(_outputDirRoot=outputDir)

    if not customOutputPath:
        return False, False

    _cc3dSimulationDataHandler.copySimulationDataFiles(customOutputPath)

    # tweak simulation files according to parameter scan file

    # construct path to the just-copied .cc3d file
    cc3dFileBaseName = os.path.basename(_cc3dSimulationDataHandler.cc3dSimulationData.path)
    cc3dFileFullName = os.path.join(customOutputPath, cc3dFileBaseName)

    # set output directory for parameter scan
    setSimulationResultStorageDirectory(customOutputPath)

    # replace values simulation files with values defined in the  the parameter scan spcs
    psu.replaceValuesInSimulationFiles(_pScanFileName=pScanFilePath, _simulationDir=customOutputPath)

    # save parameter Scan spec file with incremented ityeration
    psu.saveParameterScanState(_pScanFileName=pScanFilePath)

    return customOutputPath, cc3dFileFullName
def prepareParameterScan(_cc3dSimulationDataHandler):
    '''This fcn returns True if preparation of the next PS run was succesfull or False otherwise - this will usually happen when parameter scan reaches max iteration . 
    '''

    pScanFilePath = _cc3dSimulationDataHandler.cc3dSimulationData.parameterScanResource.path  # parameter scan file path
    cc3dProjectPath = _cc3dSimulationDataHandler.cc3dSimulationData.path
    cc3dProjectDir = _cc3dSimulationDataHandler.cc3dSimulationData.basePath

    # psu = _cc3dSimulationDataHandler.cc3dSimulationData.parameterScanResource.psu #parameter scan utils

    # checking if simulation file directory is writeable if not parameterscan cannot run properly - writeable simulation fiel directory is requirement for parameter scan
    if not os.access(cc3dProjectDir, os.W_OK):
        #         raise AssertionError('parameter Scan Error: CC3D project directory:'+cc3dProjectDir+' has to be writeable. Please change permission on the directory of the .cc3d project')
        raise AssertionError('Parameter Scan ERRORCODE=' + str(
            ParameterScanEnums.SCAN_FINISHED_OR_DIRECTORY_ISSUE) + ': : CC3D project directory:' + cc3dProjectDir + ' has to be writeable. Please change permission on the directory of the .cc3d project')
        # check if parameter scan file is writeable
    if not os.access(pScanFilePath, os.W_OK):
        raise AssertionError('Parameter Scan ERRORCODE=' + str(
            ParameterScanEnums.SCAN_FINISHED_OR_DIRECTORY_ISSUE) + ': Parameter Scan xml file :' + pScanFilePath + ' has to be writeable. Please change permission on this file')
    # raise AssertionError('parameter Scan Error: Parameter Scan xml file :'+pScanFilePath+ ' has to be writeable. Please change permission on this file')

    # We use separate ParameterScanUtils object to handle parameter scan 
    from ParameterScanUtils import ParameterScanUtils

    psu = ParameterScanUtils()
    psu.readParameterScanSpecs(pScanFilePath)

    paramScanSpecsDirName = os.path.dirname(pScanFilePath)

    outputDir = getRootOutputDir()  # output dir is determined in a way that dpes not require PyQt4  and Configuration module

    customOutputPath = psu.prepareParameterScanOutputDirs(_outputDirRoot=outputDir)

    if not customOutputPath:
        return False, False

    _cc3dSimulationDataHandler.copySimulationDataFiles(customOutputPath)

    # tweak simulation files according to parameter scan file

    # construct path to the just-copied .cc3d file
    cc3dFileBaseName = os.path.basename(_cc3dSimulationDataHandler.cc3dSimulationData.path)
    cc3dFileFullName = os.path.join(customOutputPath, cc3dFileBaseName)

    # set output directory for parameter scan
    setSimulationResultStorageDirectory(customOutputPath)

    # replace values simulation files with values defined in the  the parameter scan spcs
    psu.replaceValuesInSimulationFiles(_pScanFileName=pScanFilePath, _simulationDir=customOutputPath)

    # save parameter Scan spec file with incremented ityeration
    psu.saveParameterScanState(_pScanFileName=pScanFilePath)

    return customOutputPath, cc3dFileFullName