Ensembles
We perform Markov-chain Monte Carlo and estimate expectation values stochastically.
Ensembls are made up of configurations.
- class supervillain.configurations.Configurations(dictionary)[source]
Bases:
Extendable
,ReadWriteable
A group of configurations has fields (which you can access by doing
cfgs.field
) and other auxiliary information (one per configuration).However, you can also use
cfgs[step]
to get a dictionary with keys that correspond to the names of the fields (and the auxiliary information) and associated values.If you like you can think of a set of Configurations as a very lightweight barely-featured pandas DataFrame.
- Parameters
dictionary (dict) – A dictionary with
{key: value}
pairs, where each value is an array whose first dimension is one per configuration.
- __getitem__(index)[source]
- Parameters
index (fancy indexing) – A subset of numpy fancy indexing is supported; this selection is used for selecting configurations based on their location in the dataset, rather than their
index
. Some valid choices are7
,[1,2,3]
,slice(1,4)
,slice(1,10,2)
.- Returns
If index is an integer, returns a dictionary with key/value pairs for the requested configuration. If the index is fancier, return another set of
Configurations
.- Return type
one or many configurations
- class supervillain.ensemble.Ensemble(action)[source]
Bases:
Extendable
An ensemble of configurations importance-sampled according to the
action
.- Parameters
Action (an action) – An action which describes the path integral of interest.
- Action
The action for the ensemble.
- from_configurations(configurations)[source]
- Parameters
configurations – A set of pre-computed configurations.
- Return type
The ensemble itself, so that one can do
ensemble = Ensemble(action).from_configurations(cfgs)
.
- generate(steps, generator, start='cold', progress=<function _no_op>, starting_index=0, index_stride=1)[source]
- Parameters
steps (int) – Number of configurations to generate.
generator – Something which produces a new configuration if called as
generator.step(previous_configuration)
.start (‘cold’, or a configuration as a dictionary) – A cold start beins with the all-zero configuration. If a dictionary is passed it is used as the zeroeth configuration.
progress (something which wraps an iterator and provides a progress bar.) – In a script you might use tqdm.tqdm, and in a notebook tqdm.notebook. Defaults to no progress reporting. Must accept a desc keyword argument.
starting_index (int) – An ensemble has a
.index
which is an array of regularly-spaced integers labeling the configurations; this sets the lower value.index_stride (int) – The increment of the
.index
for each call of the generator.
- Return type
the ensemble itself, so that one can do
ensemble = GrandCanonical(action).generate(...)
.
- classmethod continue_from(ensemble, steps, progress=<function _no_op>)[source]
Use the last configuration and generator of
ensemble
to produce a new ensemble ofsteps
configurations.- Parameters
ensemble (supervillain.Ensemble or an h5py.Group that encodes such an ensemble) – The ensemble to continue. Raises a ValueError if it is not a supervillain.Ensemble or an h5py.Group with an action, generator, and at least one configuration.
steps (int) – Number of configurations to generate.
progress – As in
generate()
.
- Returns
An ensemble with
steps
new configurataions generted in the same way asensemble
.- Return type
supervillain.Ensemble
Todo
The starting weight should automatically be read in; currently not.
- measure(observables=None)[source]
If
observables
is None, measure every known primary observable on this ensemble. Otherwise measure only those observables named. If an observable is already computed, no new computation occurs.- Parameters
observables (
None
or iterable of strings naming observables.) – Observables to compute on this ensemble.- Returns
Keys are observable names, values are the measurements.
- Return type
dict
- property measured
A set of strings naming measured observables.
- autocorrelation_time(observables=None, every=False)[source]
Compute the autocorrelation time for the ensemble’s measurements. However, the autocorrelation time for any observable is only computed if that observable’s
autocorrelation()
is true for this ensemble.However, if no measurements have been made so that
measured
is empty, try every observable with a trueautocorrelation()
. This may trigger measurement, and is usually what you want; after generation you want to thermalize or decorrelate.Note
The measurement of some observables, particularly those for which
autocorrelation()
is false for this ensemble, is not triggered automatically, unless it is a prerequisite for an observable forautocorrelation()
is true.- Parameters
observables (
None
or iterable of strings naming observables.) – Which observables to consider. IfNone
, consider all previously-measured observables.every (boolean) – If
True
returns a dictionary with keys given by observable names and values the computed autocorrelation times.
- cut(start)[source]
Good for thermalization.
thermalized = ensemble.cut(start)
- Parameters
start (int) – How many configurations to drop from the beginning of the ensemble.
- Returns
An ensemble with fewer configurations.
- Return type
- every(stride)[source]
Good for decorrelation.
The generator is wrapped in
KeepEvery
so thatcontinue_from()
produces a strided follow-on ensemble.decorrelated = thermalized.every(stride)
- Parameters
stride (int) – How many configurations to skip.
- Returns
An ensemble with fewer configurations.
- Return type