def __pre_init__(self, hilbert, rule, **kwargs): r""" Constructs a Metropolis Sampler. Args: hilbert: The hilbert space to sample rule: A `MetropolisRule` to generate random transitions from a given state as well as uniform random states. n_sweeps: The number of exchanges that compose a single sweep. If None, sweep_size is equal to the number of degrees of freedom being sampled (the size of the input vector s to the machine). reset_chains: If False the state configuration is not resetted when reset() is called. n_chains: The number of Markov Chain to be run in parallel on a single process. machine_pow: The power to which the machine should be exponentiated to generate the pdf (default = 2). dtype: The dtype of the statees sampled (default = np.float32). """ # process arguments in the base args, kwargs = super().__pre_init__(hilbert=hilbert, **kwargs) kwargs["rule"] = rule # deprecation warnings if "reset_chain" in kwargs: warn_deprecation( "The keyword argument `reset_chain` is deprecated in favour of `reset_chains`" ) kwargs["reset_chains"] = kwargs.pop("reset_chain") return args, kwargs
def edges( self, color=None, *, return_color: bool = False, filter_color: Optional[int] = None, ) -> EdgeSequence: if color is not None: warn_deprecation( "The color option has been split into return_color and filter_color." ) # need to check for bool first, because bool is a subclass of int if isinstance(color, bool): return_color = color elif isinstance(color, int): filter_color = color else: raise TypeError("Incorrect type for 'color'") if not return_color and filter_color is None: return self._igraph.get_edgelist() edges_with_color = zip(self._igraph.get_edgelist(), self.edge_colors) if filter_color is not None: edges_with_color = filter(lambda x: x[1] == filter_color, edges_with_color) if return_color: return [(*e, c) for (e, c) in edges_with_color] else: return [e for (e, _) in edges_with_color]
def __pre_init__(self, hilbert, rule, **kwargs): """ Constructs a Metropolis Sampler. Args: hilbert: The Hilbert space to sample. rule: A `MetropolisRule` to generate random transitions from a given state as well as uniform random states. n_chains: The total number of independent Markov chains across all MPI ranks. Either specify this or `n_chains_per_rank`. n_chains_per_rank: Number of independent chains on every MPI rank (default = 16). n_sweeps: Number of sweeps for each step along the chain. Defaults to the number of sites in the Hilbert space. This is equivalent to subsampling the Markov chain. reset_chains: If True, resets the chain state when `reset` is called on every new sampling (default = False). machine_pow: The power to which the machine should be exponentiated to generate the pdf (default = 2). dtype: The dtype of the states sampled (default = np.float64). """ if "n_chains" not in kwargs and "n_chains_per_rank" not in kwargs: kwargs["n_chains_per_rank"] = 16 # process arguments in the base args, kwargs = super().__pre_init__(hilbert=hilbert, **kwargs) kwargs["rule"] = rule # deprecation warnings if "reset_chain" in kwargs: warn_deprecation( "The keyword argument `reset_chain` is deprecated in favour of `reset_chains`" ) kwargs["reset_chains"] = kwargs.pop("reset_chain") return args, kwargs
def __pre_init__(self, *args, **kwargs): """ Construct an exact sampler. Args: hilbert: The Hilbert space to sample. machine_pow: The power to which the machine should be exponentiated to generate the pdf (default = 2). dtype: The dtype of the states sampled (default = np.float64). """ if "n_chains" in kwargs or "n_chains_per_rank" in kwargs: warn_deprecation( "Specifying `n_chains` or `n_chains_per_rank` when constructing exact samplers is deprecated." ) return super().__pre_init__(*args, **kwargs)
def __pre_init__(self, *args, **kwargs): """ Construct an autoregressive direct sampler. Args: hilbert: The Hilbert space to sample. dtype: The dtype of the states sampled (default = np.float64). Note: `ARDirectSampler.machine_pow` has no effect. Please set the model's `machine_pow` instead. """ if "n_chains" in kwargs or "n_chains_per_rank" in kwargs: warn_deprecation( "Specifying `n_chains` or `n_chains_per_rank` when constructing exact samplers is deprecated." ) return super().__pre_init__(*args, **kwargs)
def __pre_init__(self, hilbert: AbstractHilbert, rule: MetropolisRule, **kwargs): """ Constructs a Metropolis Sampler. Args: hilbert: The Hilbert space to sample. rule: A `MetropolisRule` to generate random transitions from a given state as well as uniform random states. n_chains: The total number of independent Markov chains across all MPI ranks. Either specify this or `n_chains_per_rank`. If MPI is disabled, the two are equivalent; if MPI is enabled and `n_chains` is specified, then every MPI rank will run `n_chains/mpi.n_nodes` chains. In general, we recommend specifying `n_chains_per_rank` as it is more portable. n_chains_per_rank: Number of independent chains on every MPI rank (default = 16). n_sweeps: Number of sweeps for each step along the chain. This is equivalent to subsampling the Markov chain. (Defaults to the number of sites in the Hilbert space.) reset_chains: If True, resets the chain state when `reset` is called on every new sampling (default = False). machine_pow: The power to which the machine should be exponentiated to generate the pdf (default = 2). dtype: The dtype of the states sampled (default = np.float64). """ # Validate the inputs if not isinstance(rule, MetropolisRule): raise TypeError( f"The second positional argument, rule, must be a MetropolisRule but " f"`type(rule)={type(rule)}`." ) if "n_chains" not in kwargs and "n_chains_per_rank" not in kwargs: kwargs["n_chains_per_rank"] = 16 # process arguments in the base args, kwargs = super().__pre_init__(hilbert=hilbert, **kwargs) kwargs["rule"] = rule # deprecation warnings if "reset_chain" in kwargs: warn_deprecation( "The keyword argument `reset_chain` is deprecated in favour of `reset_chains`" ) kwargs["reset_chains"] = kwargs.pop("reset_chain") return args, kwargs