Beispiel #1
0
def test_dmc_est_sampling():
    """Testing the DMC sampling to evaluate several estimators."""

    exec_logger.info('Init sampling...')

    # TODO: Improve this test.
    exec_logger.info('Init VMC sampling...')

    vmc_chain_data = vmc_sampling.as_chain(num_steps, vmc_ini_state)
    sys_conf_set = vmc_chain_data.confs
    ar_ = vmc_chain_data.accept_rate
    print(f"Acceptance ratio: {ar_:.5g}")

    exec_logger.info('Finished sampling...')

    ini_sys_conf_set = sys_conf_set[-128:]
    dmc_ini_state = dmc_sampling.build_state(ini_sys_conf_set, ini_ref_energy)

    num_modes = 2 * BOSON_NUMBER

    ssf_est_spec = mrbp_qmc.dmc.SSFEstSpec(num_modes)
    dmc_ssf_sampling = attr.evolve(dmc_sampling, ssf_est_spec=ssf_est_spec)
    dmc_es_blocks = dmc_ssf_sampling.blocks(dmc_ini_state,
                                            num_time_steps_block,
                                            burn_in_blocks)

    es_blocks: dmc_base.T_SBlocksIter = \
        islice(dmc_es_blocks, num_blocks)

    exec_logger.info('Init DMC sampling...')

    for block in es_blocks:
        state_props = block.iter_props
        nw_iter = state_props.num_walkers
        iter_ssf = block.iter_ssf
        # print(state_props)
        ssf_block_data = iter_ssf / nw_iter[:, np.newaxis, np.newaxis]
        print(ssf_block_data)
        # print(nw_iter)
        # This helps to catch memory leaks in numba compiled functions.
        print(rtsys.get_allocation_stats())
        print('---')

    exec_logger.info('Finish DMC sampling.')
Beispiel #2
0
def test_density_est():
    """Testing the calculation of the density."""

    exec_logger.info('Init sampling...')

    # TODO: Improve this test.
    exec_logger.info('Init VMC sampling...')

    vmc_chain_data = vmc_sampling.as_chain(num_steps, vmc_ini_state)
    sys_conf_set = vmc_chain_data.confs
    ar_ = vmc_chain_data.accept_rate
    print(f"Acceptance ratio: {ar_:.5g}")

    exec_logger.info('Finished sampling...')

    ini_sys_conf_set = sys_conf_set[-128:]
    dmc_ini_state = dmc_sampling.build_state(ini_sys_conf_set, ini_ref_energy)

    num_bins = SUPERCELL_SIZE * 16

    density_est_spec = mrbp_qmc.dmc.DensityEstSpec(num_bins)
    dmc_density_sampling = attr.evolve(dmc_sampling,
                                       density_est_spec=density_est_spec)
    dmc_es_blocks = dmc_density_sampling.blocks(dmc_ini_state,
                                                num_time_steps_block,
                                                burn_in_blocks)

    es_blocks: dmc_base.T_SBlocksIter = \
        islice(dmc_es_blocks, num_blocks)

    exec_logger.info('Init DMC sampling...')

    for block in es_blocks:
        state_props = block.iter_props
        nw_iter = state_props.num_walkers
        iter_density = block.iter_density
        print(iter_density.shape)
        density_block_data = iter_density / nw_iter[:, np.newaxis, np.newaxis]
        print(density_block_data)
        # print(nw_iter)

    exec_logger.info('Finish DMC sampling.')
Beispiel #3
0
    def exec(self, model_spec: model.Spec,
             sys_conf_set: np.ndarray,
             ini_wf_abs_log_set: np.ndarray):
        """

        :param model_spec:
        :param sys_conf_set: he system configurations used for the
            minimization process.
        :param ini_wf_abs_log_set: The initial wave function values. Used
            to calculate the weights.
        :return:
        """
        num_sys_confs = self.num_sys_confs

        exec_logger.info('Starting wave function optimization...')
        exec_logger.info(f'Using {num_sys_confs} configurations to '
                         f'minimize the variance...')

        sys_conf_set = sys_conf_set[-num_sys_confs:]
        ini_wf_abs_log_set = ini_wf_abs_log_set[-num_sys_confs:]

        optimizer = model.CSWFOptimizer(model_spec,
                                        sys_conf_set,
                                        ini_wf_abs_log_set,
                                        self.ref_energy,
                                        self.use_threads,
                                        self.num_workers,
                                        self.verbose)
        opt_result = optimizer.exec()

        exec_logger.info('Wave function optimization completed.')

        return opt_result
Beispiel #4
0
    def describe_model_spec(self):
        """

        :return:
        """
        model_spec = self.model_spec
        v_zero = model_spec.lattice_depth
        lr = model_spec.lattice_ratio
        gn = model_spec.interaction_strength
        nop = model_spec.boson_number
        sc_size = model_spec.supercell_size
        rm = model_spec.tbf_contact_cutoff

        exec_logger.info('Multi-Rods system parameters:')
        exec_logger.info(f'* Lattice depth: {v_zero / ER:.3G} ER')
        exec_logger.info(f'* Lattice ratio: {lr:.3G}')
        exec_logger.info(f'* Interaction strength: {gn / ER:.3G} ER')
        exec_logger.info(f'* Number of bosons: {nop:d}')
        exec_logger.info(f'* Supercell size: {sc_size:.3G} LKP')
        exec_logger.info(f'* Variational parameters:')
        exec_logger.info(f'  * RM: {rm:.3G} LKP')
Beispiel #5
0
    def exec(self):
        """Execute the application tasks.

        :return:
        """
        app_spec_set = self.app_spec
        len_spec_set = len(app_spec_set)

        exec_logger.info(f'Starting the QMC calculations...')
        exec_logger.info(f'Starting the execution of a set of '
                         f'{len_spec_set} QMC calculations...')

        for proc_num, app_spec in enumerate(app_spec_set, 1):

            exec_logger.info("*** *** ->> ")
            exec_logger.info(f'Starting procedure ID{proc_num}...')

            # noinspection PyUnusedLocal
            result = app_spec.exec()
            # print(result)

            exec_logger.info(f'Procedure ID{proc_num} completed.')
            exec_logger.info("<<- *** ***")

        exec_logger.info(f'All the QMC calculations have completed.')