Exemplo n.º 1
0
    def __init__(self,job_script, job_name, run_path, num_cpu, 
                    status_file, ok_file, exit_file, 
                    done_callback_function, exit_callback_function, callback_arguments, max_runtime=None):
        self.done_callback_function = done_callback_function
        self.exit_callback_function = exit_callback_function
        self.callback_arguments = callback_arguments
        argc = 1
        argv = StringList()
        argv.append(run_path)

        self._thread_status = ThreadStatus.READY
        self._thread = None
        self._mutex = Lock()

        self.run_path = run_path
        self._max_runtime = max_runtime
        self._start_time = None
        self._end_time = None
        c_ptr = self._alloc(job_name, run_path, job_script, argc, argv, num_cpu,
                                ok_file, status_file, exit_file, 
                                None, None, None, None)

        if c_ptr is not None:
            super(JobQueueNode, self).__init__(c_ptr)
        else:
            raise ValueError("Unable to create job node object")
Exemplo n.º 2
0
    def test_append(self):
        s1 = StringList(["A", "B"])
        s1.append("C")

        s2 = StringList(["A", "B", "C"])
        self.assertEqual(s1, ["A", "B", "C"])
        self.assertEqual(s1, s2)
        self.assertFalse(s1 == ["A", "B", "D"])
        self.assertFalse(s1 == ["A", "B", "C", "D"])

        pfx = "StringList(size"  # __repr__
        self.assertEqual(pfx, repr(s2)[:len(pfx)])
Exemplo n.º 3
0
    def test_front_back(self):
        s = StringList()
        with self.assertRaises(LookupError):
            s.front()

        with self.assertRaises(LookupError):
            s.back()

        s.append("S1")
        s.append("S2")
        s.append("S3")

        self.assertEqual("S1", s.front())
        self.assertEqual("S3", s.back())
Exemplo n.º 4
0
    def __init__(self, job_script, job_name, run_path, num_cpu, status_file,
                 ok_file, exit_file, done_callback_function,
                 exit_callback_function, callback_arguments):
        self.done_callback_function = done_callback_function
        self.exit_callback_function = exit_callback_function
        self.callback_arguments = callback_arguments

        argc = 1
        argv = StringList()
        argv.append(run_path)
        self.started = False
        self.run_path = run_path
        c_ptr = self._alloc(job_name, run_path, job_script, argc, argv,
                            num_cpu, ok_file, status_file, exit_file, None,
                            None, None, None)

        if c_ptr is not None:
            super(JobQueueNode, self).__init__(c_ptr)
        else:
            raise ValueError("Unable to create job node object")
Exemplo n.º 5
0
    def load(cls,
             smspec_file,
             unsmry_file,
             key_join_string=":",
             include_restart=True):
        if not os.path.isfile(smspec_file):
            raise IOError("No such file: %s" % smspec_file)

        if not os.path.isfile(unsmry_file):
            raise IOError("No such file: %s" % unsmry_file)

        data_files = StringList()
        data_files.append(unsmry_file)
        c_ptr = cls._fread_alloc(smspec_file, data_files, key_join_string,
                                 include_restart)
        if c_ptr is None:
            raise IOError("Failed to create summary instance")

        ecl_sum = cls.createPythonObject(c_ptr)
        ecl_sum._load_case = smspec_file
        return ecl_sum
Exemplo n.º 6
0
    def __init__(self, config_content=None, config_dict=None):

        if config_content is not None and config_dict is not None:
            raise ValueError(
                "Error: EclConfig can not be instantiated with multiple config objects"
            )
        c_ptr = None
        if config_dict is None:
            c_ptr = self._alloc(config_content)

        if config_dict is not None:
            # ECLBASE_KEY
            have_eclbase = config_dict.get(ConfigKeys.ECLBASE) is not None

            # DATA_FILE_KEY
            data_file = config_dict.get(ConfigKeys.DATA_FILE)
            if data_file is not None:
                data_file = os.path.realpath(data_file)
                if not os.path.isfile(data_file):
                    raise ValueError("Error: data file is not a file")

            # GRID_KEY
            grid = None
            grid_file = config_dict.get(ConfigKeys.GRID)
            if grid_file is not None:
                grid_file = os.path.realpath(grid_file)
                if not os.path.isfile(grid_file):
                    raise ValueError("Error: grid file is not a file")
                grid = EclGrid.load_from_file(grid_file)

            # REFCASE_KEY
            refcase_default = config_dict.get(ConfigKeys.REFCASE)
            if refcase_default is not None:
                refcase_default = os.path.realpath(refcase_default)

            # REFCASE_LIST_KEY
            refcase_list = StringList()
            for refcase in config_dict.get(ConfigKeys.REFCASE_LIST, []):
                refcase_list.append(refcase)

            # INIT_SECTION_KEY
            init_section = config_dict.get(ConfigKeys.INIT_SECITON)

            # END_DATE_KEY
            end_date = CTime(
                datetime.strptime(
                    config_dict.get(ConfigKeys.END_DATE, "31/12/1969"),
                    "%d/%m/%Y"))

            # SCHEDULE_PREDICTION_FILE_KEY
            schedule_prediction_file = config_dict.get(
                ConfigKeys.SCHEDULE_PREDICTION_FILE)

            c_ptr = self._alloc_full(have_eclbase, data_file, grid,
                                     refcase_default, refcase_list,
                                     init_section, end_date,
                                     schedule_prediction_file)
            if grid is not None:
                grid.convertToCReference(None)

        if c_ptr:
            super(EclConfig, self).__init__(c_ptr)
        else:
            raise RuntimeError(
                'Internal error: Failed constructing EclConfig!')
Exemplo n.º 7
0
    def __init__(self, config_content=None, config_dict=None):

        if config_content is not None and config_dict is not None:
            raise ValueError(
                "Error: EclConfig can not be instantiated with multiple config objects"
            )
        c_ptr = None
        if config_dict is None:
            c_ptr = self._alloc(config_content)

        if config_dict is not None:
            # ECLBASE_KEY
            have_eclbase = config_dict.get(ConfigKeys.ECLBASE) is not None

            # DATA_FILE_KEY
            data_file = config_dict.get(ConfigKeys.DATA_FILE)
            if data_file is not None:
                data_file = os.path.realpath(data_file)
                if not os.path.isfile(data_file):
                    raise ValueError("Error: data file is not a file")

            # GRID_KEY
            grid = None
            grid_file = config_dict.get(ConfigKeys.GRID)
            if grid_file is not None:
                grid_file = os.path.realpath(grid_file)
                if not os.path.isfile(grid_file):
                    raise ValueError("Error: grid file is not a file")
                grid = EclGrid.load_from_file(grid_file)

            # REFCASE_KEY
            refcase_default = config_dict.get(ConfigKeys.REFCASE)
            if refcase_default is not None:
                refcase_default = os.path.realpath(refcase_default)

            # REFCASE_LIST_KEY
            refcase_list = StringList()
            for refcase in config_dict.get(ConfigKeys.REFCASE_LIST, []):
                refcase_list.append(refcase)

            # END_DATE_KEY
            try:
                end_date = CTime(
                    datetime.strptime(
                        config_dict.get(ConfigKeys.END_DATE, "1969-12-31"),
                        "%Y-%m-%d"))
            except ValueError:
                print(
                    "Deprecation warning: The date format DD/MM/YYYY is deprecated, "
                    "and its support will be removed in a future release. "
                    "Please use ISO date format YYYY-MM-DD.")
                end_date = CTime(
                    datetime.strptime(
                        config_dict.get(ConfigKeys.END_DATE, "31/12/1969"),
                        "%d/%m/%Y"))

            # SCHEDULE_PREDICTION_FILE_KEY
            schedule_prediction_file = config_dict.get(
                ConfigKeys.SCHEDULE_PREDICTION_FILE)

            c_ptr = self._alloc_full(
                have_eclbase,
                data_file,
                grid,
                refcase_default,
                refcase_list,
                end_date,
                schedule_prediction_file,
            )
            if grid is not None:
                grid.convertToCReference(None)

        if c_ptr:
            super().__init__(c_ptr)
        else:
            raise RuntimeError(
                "Internal error: Failed constructing EclConfig!")
Exemplo n.º 8
0
 def test_append_not_string(self):
     s = StringList()
     s.append(10)
     self.assertEqual(len(s), 1)
     self.assertEqual(s[0], "10")