コード例 #1
0
    def record_derivatives_driver(self, recording_requester, data, metadata):
        """
        Record derivatives data from a Driver.

        Parameters
        ----------
        recording_requester : object
            Driver in need of recording.
        data : dict
            Dictionary containing derivatives keyed by 'of,wrt' to be recorded.
        metadata : dict
            Dictionary containing execution metadata.
        """
        if self.connection:

            data_array = dict_to_structured_array(data)
            data_blob = array_to_blob(data_array)

            with self.connection as c:
                c = c.cursor()  # need a real cursor for lastrowid

                c.execute(
                    "INSERT INTO driver_derivatives(counter, iteration_coordinate, "
                    "timestamp, success, msg, derivatives) VALUES(?,?,?,?,?,?)",
                    (self._counter, self._iteration_coordinate,
                     metadata['timestamp'], metadata['success'],
                     metadata['msg'], data_blob))
コード例 #2
0
    def record_iteration_problem(self, problem, data, metadata):
        """
        Record data and metadata from a Problem.

        Parameters
        ----------
        problem : Problem
            Problem in need of recording.
        data : dict
            Dictionary containing desvars, objectives, and constraints.
        metadata : dict
            Dictionary containing execution metadata.
        """
        if self.connection:
            outputs = data['output']
            inputs = data['input']
            residuals = data['residual']

            driver = problem.driver
            if problem.recording_options['record_derivatives'] and \
               driver._designvars and driver._responses:
                totals = data['totals']
            else:
                totals = OrderedDict([])
            totals_array = dict_to_structured_array(totals)
            totals_blob = array_to_blob(totals_array)

            # convert to list so this can be dumped as JSON
            for in_out_resid in (inputs, outputs, residuals):
                if in_out_resid is None:
                    continue
                for var in in_out_resid:
                    in_out_resid[var] = make_serializable(in_out_resid[var])

            outputs_text = json.dumps(outputs)
            inputs_text = json.dumps(inputs)
            residuals_text = json.dumps(residuals)

            abs_err = data['abs']
            rel_err = data['rel']

            with self.connection as c:
                c = c.cursor()  # need a real cursor for lastrowid

                c.execute(
                    "INSERT INTO problem_cases(counter, case_name, "
                    "timestamp, success, msg, inputs, outputs, residuals, jacobian, "
                    "abs_err, rel_err ) "
                    "VALUES(?,?,?,?,?,?,?,?,?,?,?)",
                    (self._counter, metadata['name'], metadata['timestamp'],
                     metadata['success'], metadata['msg'], inputs_text,
                     outputs_text, residuals_text, totals_blob, abs_err,
                     rel_err))

                c.execute(
                    "INSERT INTO global_iterations(record_type, rowid, source) VALUES(?,?,?)",
                    ('problem', c.lastrowid, metadata['name']))