Esempio n. 1
0
 def test_get_uuid(self, uuid_function):
     uuid_function.return_value = 12
     identifier = uuid.get_uuid()
     self.assertEqual(identifier, 12)
     # On the first call the uuid function should be called, on the second not
     uuid_function.assert_called_once_with()
     uuid_function.reset_mock()
     identifier = uuid.get_uuid()
     self.assertEqual(identifier, 12)
     uuid_function.assert_not_called()
Esempio n. 2
0
    def write(self, extracted_global_state: Sequence[Node]) -> None:
        """
        Write the extracted global state to a .pdb file.

        Parameters
        ----------
        extracted_global_state : Sequence[base.node.Node]
            The extracted global state.
        """
        super().write(extracted_global_state)
        for root_cnode in extracted_global_state:
            for leaf_node in yield_leaf_nodes(root_cnode):
                self._get_atom(leaf_node.value.identifier
                               ).position = leaf_node.value.position
        with Writer(self._filename_without_ending +
                    str(self._current_file_index) + ".pdb",
                    self._number_of_atoms,
                    multiframe=False,
                    remarks="RUN IDENTIFICATION HASH: {0}".format(
                        get_uuid())) as writer:
            # MDAnalysis prints UserWarnings that not so important attributes weren't set which we ignore
            with warnings.catch_warnings():
                warnings.simplefilter("ignore", UserWarning)
                writer.write(self._universe.atoms)
        self._current_file_index += 1
Esempio n. 3
0
def main(argv: Sequence[str]) -> None:
    """
    Use the argument strings to run the JeLLyFysh application.

    First the argument strings are parsed, and then the logging is set up. The configuration file specified in the
    argument strings is parsed. Based on the configuration file, the setting package is initialized and the mediator
    is constructed by the JeLLyFysh factory.
    The run method of the mediator is executed until an EndOfRun exception is raised. This invokes the post_run method
    of the mediator and ends the run of the application.

    Parameters
    ----------
    argv : Sequence[str]
        The argument strings.
    """
    args = parse_options(argv)
    logger = set_up_logging(args)

    logger.info("Run identification hash: {0}".format(get_uuid()))
    logger.info(
        "Underlying platform (determined via platform.platform(aliased=True): {0}"
        .format(platform.platform(aliased=True)))

    logger.info(
        "Setting up the run based on the configuration file {0}.".format(
            args.config_file))
    config = read_config(args.config_file)
    factory.build_from_config(config,
                              to_camel_case(config.get("Run", "setting")),
                              "setting")
    mediator = factory.build_from_config(
        config, to_camel_case(config.get("Run", "mediator")), "mediator")
    used_sections = factory.used_sections
    for section in config.sections():
        if section not in used_sections and section != "Run":
            logger.warning(
                "The section {0} in the .ini file has not been used!".format(
                    section))

    logger.info("Running the event-chain Monte Carlo simulation.")
    start_time = time.time()
    try:
        mediator.run()
    except EndOfRun:
        logger.info("EndOfRun exception has been raised.")
    end_time = time.time()

    logger.info("Running the post_run method.")
    mediator.post_run()
    logger.info("Runtime of the simulation: --- %s seconds ---" %
                (end_time - start_time))
Esempio n. 4
0
    def __init__(self, filename: str) -> None:
        """
        The constructor of the HardBufferedTextWriter class.

        This method opens the temporary file and writes the run identification hash into it.

        Parameters
        ----------
        filename : str
            The filename.
        """
        self._filename = filename
        self._tmp_file = open(filename + '.tmp', 'w')
        print("# Run identification hash: {0}".format(get_uuid()), file=self)
Esempio n. 5
0
def main(argv: Sequence[str]) -> None:
    """
    Use the argument strings to resume a dumped run of the JeLLyFysh application.

    First the argument strings are parsed, and then the logging is set up. The dumping file specified in the
    argument strings is parsed.
    Based on the dumping file, the setting package is initialized, the mediator is restored and the state of the random
    module is set.
    The run method of the mediator is executed until an EndOfRun exception is raised. This invokes the post_run method
    of the mediator and ends the resumed run of the application.

    Parameters
    ----------
    argv : Sequence[str]
        The argument strings.
    """
    args = parse_options(argv)
    logger = set_up_logging(args)

    logger.info("Run identification hash: {0}".format(get_uuid()))
    logger.info(
        "Underlying platform (determined via platform.platform(aliased=True): {0}"
        .format(platform.platform(aliased=True)))

    logger.info("Resuming run based on the dumping file {0}.".format(
        args.dumping_file))
    with open(args.dumping_file, "rb") as file:
        mediator, dumped_setting, dumped_random_state = dill.load(file)
    mediator.update_logging()
    setting.__dict__.update(dumped_setting.__dict__)
    random.setstate(dumped_random_state)

    if args.no_output:
        logger.info("Deactivating output.")
        mediator.deactivate_output()

    logger.info("Resuming the event-chain Monte Carlo simulation.")
    start_time = time.time()
    try:
        mediator.run()
    except EndOfRun:
        logger.info("EndOfRun exception has been raised.")
    end_time = time.time()

    logger.info("Running the post_run method.")
    mediator.post_run()
    logger.info("Runtime of the resumed simulation: --- %s seconds ---" %
                (end_time - start_time))