def write_trial(self, logger, test_trial=False):
        """
        Make trial directory, trial summary, and write trial summary.

        :param logger: SubjectLogger.
        :param test_trial: True if test trial, False otherwise. Default False.
        :return: Nothing.
        """
        # i = len(logger.trial_seq)-1
        # trial = logger.trial_seq[i]
        i = logger.trial_amount - 1
        trial = logger.trial_seq[-1]

        trial_dir = self.subject_path + "/trial" + str(i)
        # if test_trial:
        #     trial_dir = trial_dir + '_test'
        os.makedirs(trial_dir)
        trial_summary_filename_base = trial_dir + "/trial" + str(
            i) + "_summary"

        trial_str = jsonpickle.encode(trial)

        # write to pickle and json
        write_pickle(trial, trial_summary_filename_base + ".pkl")
        pretty_write(trial_str, trial_summary_filename_base + ".json")

        # remove the trial after writing to disk
        logger.trial_seq = []
    def write(self, logger, agent):
        """
        Write subject summary log.

        :param logger: SubjectLogger object.
        :param agent: Agent object.
        :return: Nothing.
        """
        # json_results = self.JSONify_subject(logger)

        logging.info("Writing subject data to: {}".format(self.subject_path))
        subject_summary_filename_base = (self.subject_path + "/" +
                                         logger.subject_id + "_summary")

        subject_summary_str = jsonpickle.encode(logger)

        write_pickle(logger, subject_summary_filename_base + ".pkl")
        pretty_write(subject_summary_str,
                     subject_summary_filename_base + ".json")

        # write out the RL agent
        if agent is not None:
            agent_cpy = copy.copy(agent)
            things_to_delete = ["env", "target_model", "model", "memory"]
            for thing_to_delete in things_to_delete:
                if hasattr(agent_cpy, thing_to_delete):
                    delattr(agent_cpy, thing_to_delete)
            things_to_delete = ["tensorboard_writer", "terminal_writer"]
            for thing_to_delete in things_to_delete:
                if hasattr(agent_cpy.writer, thing_to_delete):
                    delattr(agent_cpy.writer, thing_to_delete)
            if hasattr(agent_cpy, "profiler"):
                agent_cpy.profiler.disable()
                agent_cpy.profiler.dump_stats(self.subject_path + "/" +
                                              logger.subject_id +
                                              "_profile.pstat")
                delattr(agent_cpy, "profiler")
            agent_file_name_base = (self.subject_path + "/" +
                                    logger.subject_id + "_agent")

            agent_str = jsonpickle.encode(agent_cpy)

            write_pickle(agent_cpy, agent_file_name_base + ".pkl")
            pretty_write(agent_str, agent_file_name_base + ".json")
Esempio n. 3
0
 def write_to_json(self, filename):
     pretty_write(jsonpickle, filename)
Esempio n. 4
0
 def write_to_json(self, filename):
     json_encoding_str = jsonpickle.encode(self)
     pretty_write(jsonpickle, filename)