Skip to content

Nearest-Neighbor Quantum Monte Carlo

oqd_heisenberg_ion.simulators.qmc.nearest_neighbor.preprocessor

NearestNeighborQMC

Bases: Preprocessor

Preprocessor subclass for nearest neighbor QMC. Configures the parameter sets and writes the input file containing the preprocessor updated parameter sets.

Source code in src/oqd_heisenberg_ion/simulators/qmc/nearest_neighbor/preprocessor.py
class NearestNeighborQMC(Preprocessor):
    """
    Preprocessor subclass for nearest neighbor QMC. Configures the parameter sets and writes the input file containing the preprocessor updated parameter sets.
    """

    allowed_hamiltonians = {"afm_heisenberg_fm_Z", "XY", "fm_heisenberg_fm_Z"}

    def __init__(self, parameter_set_list):
        """
        executes the preprocessing logic for nearest neighbor qmc

        Args:
            parameter_set_list (list[dict]): list of unparsed parameters sets
        """

        super().__init__(parameter_set_list)

        self.driver_inputs = []

    def preprocess(self):
        """
        configures the input parameter sets for the nearest neighbor qmc calculation,
        checks that a single root folder is specified, creates the simulation output folder
        and validates the uuids.
        """

        self.check_single_input("root_folder")

        self.simulation_folder = self.create_output_folder()

        self.check_unique_uuids()

        self.configure_simulation()

        return self.driver_inputs

    def configure_simulation(self):
        """
        configures the input parameter sets and writes a tab delimited file containing the configured parameters
        """

        for i in range(self.num_parameter_sets):
            parameter_set = self.parameter_set_list[i]

            self.configure_parameter_set(parameter_set)

        self.write_input_file()

    def configure_parameter_set(self, parameter_args):
        """
        configures a single parameter set, specifies and creates the parameter set output folder, defines and validates the system and the sampling parameters for nearest neighbor qmc

        Args:
            parameter_args (dict): unparsed parameter set
        """

        input_config = InputParser(**parameter_args)
        system_args = input_config.simulation_config["system"]

        misc_args = input_config.simulation_config["misc"]
        run_id = self.get_run_id(misc_args)
        misc_args["uuid"] = run_id
        misc_args["output_folder_name"] = self.output_folder_name

        misc_args["simulation_folder"] = self.simulation_folder

        run_folder = self.create_run_folder(misc_args)
        misc_args["run_folder"] = run_folder

        system = System(**system_args)
        system.geometry.build()

        self.validate_system(system)

        system_args = system.update_parameters(system_args)

        simulation_args = input_config.simulation_config["simulation"]
        sampling_args = input_config.simulation_config["sampling"]
        combined_args = simulation_args | sampling_args

        sampling_params = SamplingParameters(**combined_args)
        sampling_args = sampling_params.update_parameters(sampling_args)

        simulation_parameters = SSEParameters(system, sampling_params, run_folder)

        self.driver_inputs.append(simulation_parameters)

        self.processed_configs.append(input_config.simulation_config)

    def validate_system(self, system):
        """
        validates the system for nearest neighbor qmc

        Args:
            system (System): object defining the system to be simulated

        Raises:
            Exception: if the specified Hamiltonian is not allowed for the nearest neighbor qmc simulator
            Exception: if the hamiltonian is anti-ferromagnetic and the geometry is not bipartite
            Exception: if J <= 0 and the hamiltonian is not anti-ferromagnetic
            Exception: if the interaction range is not nearest neighbor
        """

        if system.model_name not in self.allowed_hamiltonians:
            raise Exception(
                "Unrecognized Hamiltonian name for nearest-neighbor simulator. "
                f"Allowed Hamiltonians are: {self.allowed_hamiltonians}"
            )

        if system.model_name == "afm_heisenberg_fm_Z":
            if not system.geometry.bipartite:
                raise Exception("afm_heisenberg_fm_Z Hamiltonian requires a bipartite lattice\n")

        if system.hamiltonian_parameters.J <= 0 and system.model_name != "afm_heisenberg_fm_Z":
            raise Exception(
                "J sets the energy scale. It must be a positive number for QMC unless the model is afm_heisenberg_fm_Z on a bipartite lattice\n"
            )

        if system.interaction_range != "nearest_neighbor":
            print(system.interaction_range)
            raise Exception("NearestNeighborQMC can only be used for nearest-neighbor interactions\n")

__init__

executes the preprocessing logic for nearest neighbor qmc

Parameters:

  • parameter_set_list (list[dict]) –

    list of unparsed parameters sets

Source code in src/oqd_heisenberg_ion/simulators/qmc/nearest_neighbor/preprocessor.py
def __init__(self, parameter_set_list):
    """
    executes the preprocessing logic for nearest neighbor qmc

    Args:
        parameter_set_list (list[dict]): list of unparsed parameters sets
    """

    super().__init__(parameter_set_list)

    self.driver_inputs = []

preprocess

configures the input parameter sets for the nearest neighbor qmc calculation, checks that a single root folder is specified, creates the simulation output folder and validates the uuids.

Source code in src/oqd_heisenberg_ion/simulators/qmc/nearest_neighbor/preprocessor.py
def preprocess(self):
    """
    configures the input parameter sets for the nearest neighbor qmc calculation,
    checks that a single root folder is specified, creates the simulation output folder
    and validates the uuids.
    """

    self.check_single_input("root_folder")

    self.simulation_folder = self.create_output_folder()

    self.check_unique_uuids()

    self.configure_simulation()

    return self.driver_inputs

configure_simulation

configures the input parameter sets and writes a tab delimited file containing the configured parameters

Source code in src/oqd_heisenberg_ion/simulators/qmc/nearest_neighbor/preprocessor.py
def configure_simulation(self):
    """
    configures the input parameter sets and writes a tab delimited file containing the configured parameters
    """

    for i in range(self.num_parameter_sets):
        parameter_set = self.parameter_set_list[i]

        self.configure_parameter_set(parameter_set)

    self.write_input_file()

configure_parameter_set

configures a single parameter set, specifies and creates the parameter set output folder, defines and validates the system and the sampling parameters for nearest neighbor qmc

Parameters:

  • parameter_args (dict) –

    unparsed parameter set

Source code in src/oqd_heisenberg_ion/simulators/qmc/nearest_neighbor/preprocessor.py
def configure_parameter_set(self, parameter_args):
    """
    configures a single parameter set, specifies and creates the parameter set output folder, defines and validates the system and the sampling parameters for nearest neighbor qmc

    Args:
        parameter_args (dict): unparsed parameter set
    """

    input_config = InputParser(**parameter_args)
    system_args = input_config.simulation_config["system"]

    misc_args = input_config.simulation_config["misc"]
    run_id = self.get_run_id(misc_args)
    misc_args["uuid"] = run_id
    misc_args["output_folder_name"] = self.output_folder_name

    misc_args["simulation_folder"] = self.simulation_folder

    run_folder = self.create_run_folder(misc_args)
    misc_args["run_folder"] = run_folder

    system = System(**system_args)
    system.geometry.build()

    self.validate_system(system)

    system_args = system.update_parameters(system_args)

    simulation_args = input_config.simulation_config["simulation"]
    sampling_args = input_config.simulation_config["sampling"]
    combined_args = simulation_args | sampling_args

    sampling_params = SamplingParameters(**combined_args)
    sampling_args = sampling_params.update_parameters(sampling_args)

    simulation_parameters = SSEParameters(system, sampling_params, run_folder)

    self.driver_inputs.append(simulation_parameters)

    self.processed_configs.append(input_config.simulation_config)

validate_system

validates the system for nearest neighbor qmc

Parameters:

  • system (System) –

    object defining the system to be simulated

Raises:

  • Exception

    if the specified Hamiltonian is not allowed for the nearest neighbor qmc simulator

  • Exception

    if the hamiltonian is anti-ferromagnetic and the geometry is not bipartite

  • Exception

    if J <= 0 and the hamiltonian is not anti-ferromagnetic

  • Exception

    if the interaction range is not nearest neighbor

Source code in src/oqd_heisenberg_ion/simulators/qmc/nearest_neighbor/preprocessor.py
def validate_system(self, system):
    """
    validates the system for nearest neighbor qmc

    Args:
        system (System): object defining the system to be simulated

    Raises:
        Exception: if the specified Hamiltonian is not allowed for the nearest neighbor qmc simulator
        Exception: if the hamiltonian is anti-ferromagnetic and the geometry is not bipartite
        Exception: if J <= 0 and the hamiltonian is not anti-ferromagnetic
        Exception: if the interaction range is not nearest neighbor
    """

    if system.model_name not in self.allowed_hamiltonians:
        raise Exception(
            "Unrecognized Hamiltonian name for nearest-neighbor simulator. "
            f"Allowed Hamiltonians are: {self.allowed_hamiltonians}"
        )

    if system.model_name == "afm_heisenberg_fm_Z":
        if not system.geometry.bipartite:
            raise Exception("afm_heisenberg_fm_Z Hamiltonian requires a bipartite lattice\n")

    if system.hamiltonian_parameters.J <= 0 and system.model_name != "afm_heisenberg_fm_Z":
        raise Exception(
            "J sets the energy scale. It must be a positive number for QMC unless the model is afm_heisenberg_fm_Z on a bipartite lattice\n"
        )

    if system.interaction_range != "nearest_neighbor":
        print(system.interaction_range)
        raise Exception("NearestNeighborQMC can only be used for nearest-neighbor interactions\n")

oqd_heisenberg_ion.simulators.qmc.nearest_neighbor.preprocess

sampling_params

SamplingParameters

object defining the sampling parameters for nearest-neighbor SSE

Source code in src/oqd_heisenberg_ion/simulators/qmc/nearest_neighbor/preprocess/sampling_params.py
class SamplingParameters:
    """
    object defining the sampling parameters for nearest-neighbor SSE
    """

    def __init__(self, **sampling_args):
        """
        extracts the sampling parameters needed for nearest neighbor QMC. Sets defaults for optional parameters if needed

        Args:
            **sampling_args (dict): key word arguments that contain the sampling parameters for nearest neighbor QMC
        """

        self.T = sampling_args["T"]
        self.beta = 1.0 / self.T

        self.equilibration_steps = sampling_args["equilibration_steps"]
        self.mc_steps = sampling_args["simulation_steps"]

        self.initial_operator_list_size = self.set_optional_parameter("initial_operator_list_size", sampling_args, 50)
        self.operator_list_update_multiplier = self.set_optional_parameter(
            "operator_list_update_multiplier", sampling_args, 1.25
        )
        self.initial_configuration_index = self.set_optional_parameter("initial_configuration_index", sampling_args, 0)

        self.initial_config_seed = self.set_optional_parameter("initial_config_seed", sampling_args, 17951893)
        self.disconnected_spin_flip_seed = self.set_optional_parameter(
            "disconnected_spin_flip_seed", sampling_args, 674604219
        )
        self.off_diagonal_update_seed = self.set_optional_parameter(
            "off_diagonal_update_seed", sampling_args, 961025794
        )
        self.metropolis_insert_seed = self.set_optional_parameter("metropolis_insert_seed", sampling_args, 148014634)
        self.metropolis_remove_seed = self.set_optional_parameter("metropolis_remove_seed", sampling_args, 148014634)
        self.diagonal_update_seed = self.set_optional_parameter("diagonal_update_seed", sampling_args, 734634223)
        self.exit_leg_seed = self.set_optional_parameter("exit_leg_seed", sampling_args, 2345346346)

    def set_optional_parameter(self, key, sampling_args, default_val):
        """
        checks if specified optional sampling parameters for nearest neighbor QMC is provided, if an input is not provided, a default value is returned

        Args:
            key (str): parameter key
            sampling_args (dict): user specified key value arguments for parameter set
            default_val (float): default value of SSE sampling parameter

        Returns:
            (float): value to be used for parameter specified by key
        """

        if key in sampling_args:
            var = sampling_args[key]
        else:
            var = default_val

        return var

    def update_parameters(self, parameter_dict):
        """
        updates the parameter dict associated with a parameter set with nearest neighbor SSE parameters

        Returns:
            (dict): parameter set
        """

        parameter_dict["initial_operator_list_size"] = self.initial_operator_list_size
        parameter_dict["operator_list_update_multiplier"] = self.operator_list_update_multiplier
        parameter_dict["initial_configuration_index"] = self.initial_configuration_index

        parameter_dict["initial_config_seed"] = self.initial_config_seed
        parameter_dict["metropolis_insert_seed"] = self.metropolis_insert_seed
        parameter_dict["metropolis_remove_seed"] = self.metropolis_remove_seed
        parameter_dict["disconnected_spin_flip_seed"] = self.disconnected_spin_flip_seed
        parameter_dict["off_diagonal_update_seed"] = self.off_diagonal_update_seed
        parameter_dict["exit_leg_seed"] = self.exit_leg_seed
        parameter_dict["diagonal_update_seed"] = self.diagonal_update_seed

        return parameter_dict
__init__

extracts the sampling parameters needed for nearest neighbor QMC. Sets defaults for optional parameters if needed

Parameters:

  • **sampling_args (dict, default: {} ) –

    key word arguments that contain the sampling parameters for nearest neighbor QMC

Source code in src/oqd_heisenberg_ion/simulators/qmc/nearest_neighbor/preprocess/sampling_params.py
def __init__(self, **sampling_args):
    """
    extracts the sampling parameters needed for nearest neighbor QMC. Sets defaults for optional parameters if needed

    Args:
        **sampling_args (dict): key word arguments that contain the sampling parameters for nearest neighbor QMC
    """

    self.T = sampling_args["T"]
    self.beta = 1.0 / self.T

    self.equilibration_steps = sampling_args["equilibration_steps"]
    self.mc_steps = sampling_args["simulation_steps"]

    self.initial_operator_list_size = self.set_optional_parameter("initial_operator_list_size", sampling_args, 50)
    self.operator_list_update_multiplier = self.set_optional_parameter(
        "operator_list_update_multiplier", sampling_args, 1.25
    )
    self.initial_configuration_index = self.set_optional_parameter("initial_configuration_index", sampling_args, 0)

    self.initial_config_seed = self.set_optional_parameter("initial_config_seed", sampling_args, 17951893)
    self.disconnected_spin_flip_seed = self.set_optional_parameter(
        "disconnected_spin_flip_seed", sampling_args, 674604219
    )
    self.off_diagonal_update_seed = self.set_optional_parameter(
        "off_diagonal_update_seed", sampling_args, 961025794
    )
    self.metropolis_insert_seed = self.set_optional_parameter("metropolis_insert_seed", sampling_args, 148014634)
    self.metropolis_remove_seed = self.set_optional_parameter("metropolis_remove_seed", sampling_args, 148014634)
    self.diagonal_update_seed = self.set_optional_parameter("diagonal_update_seed", sampling_args, 734634223)
    self.exit_leg_seed = self.set_optional_parameter("exit_leg_seed", sampling_args, 2345346346)
set_optional_parameter

checks if specified optional sampling parameters for nearest neighbor QMC is provided, if an input is not provided, a default value is returned

Parameters:

  • key (str) –

    parameter key

  • sampling_args (dict) –

    user specified key value arguments for parameter set

  • default_val (float) –

    default value of SSE sampling parameter

Returns:

  • float

    value to be used for parameter specified by key

Source code in src/oqd_heisenberg_ion/simulators/qmc/nearest_neighbor/preprocess/sampling_params.py
def set_optional_parameter(self, key, sampling_args, default_val):
    """
    checks if specified optional sampling parameters for nearest neighbor QMC is provided, if an input is not provided, a default value is returned

    Args:
        key (str): parameter key
        sampling_args (dict): user specified key value arguments for parameter set
        default_val (float): default value of SSE sampling parameter

    Returns:
        (float): value to be used for parameter specified by key
    """

    if key in sampling_args:
        var = sampling_args[key]
    else:
        var = default_val

    return var
update_parameters

updates the parameter dict associated with a parameter set with nearest neighbor SSE parameters

Returns:

  • dict

    parameter set

Source code in src/oqd_heisenberg_ion/simulators/qmc/nearest_neighbor/preprocess/sampling_params.py
def update_parameters(self, parameter_dict):
    """
    updates the parameter dict associated with a parameter set with nearest neighbor SSE parameters

    Returns:
        (dict): parameter set
    """

    parameter_dict["initial_operator_list_size"] = self.initial_operator_list_size
    parameter_dict["operator_list_update_multiplier"] = self.operator_list_update_multiplier
    parameter_dict["initial_configuration_index"] = self.initial_configuration_index

    parameter_dict["initial_config_seed"] = self.initial_config_seed
    parameter_dict["metropolis_insert_seed"] = self.metropolis_insert_seed
    parameter_dict["metropolis_remove_seed"] = self.metropolis_remove_seed
    parameter_dict["disconnected_spin_flip_seed"] = self.disconnected_spin_flip_seed
    parameter_dict["off_diagonal_update_seed"] = self.off_diagonal_update_seed
    parameter_dict["exit_leg_seed"] = self.exit_leg_seed
    parameter_dict["diagonal_update_seed"] = self.diagonal_update_seed

    return parameter_dict

SSEParameters

Object to collect all SSE parameters that need to be passed to the nearest neighbor QMC engine

Source code in src/oqd_heisenberg_ion/simulators/qmc/nearest_neighbor/preprocess/sampling_params.py
class SSEParameters:
    """
    Object to collect all SSE parameters that need to be passed to the nearest neighbor QMC engine
    """

    def __init__(self, system, sampling_parameters, run_folder):

        self.system = system
        self.sampling_parameters = sampling_parameters

        self.run_folder = run_folder