def main():
    # Initialize Isle.
    # This sets up the command line interface, defines a barebones argument parser,
    # and parses and returns parsed arguments.
    # More complex parsers can be automatically defined or passed in manually.
    # See, e.g., `hmcThermalization.py` or `measure.py` examples.
    isle.initialize("default")

    # Get a logger. Use this instead of print() to output any and all information.
    log = getLogger("HMC")

    # Load the spatial lattice.
    # Note: This command loads a lattice that is distributed together with Isle.
    #       In order to load custom lattices from a file, use
    #       either  isle.LATTICES.loadExternal(filename)
    #       or  isle.fileio.yaml.loadLattice(filename)
    lat = isle.LATTICES[LATTICE]
    # Lattice files usually only contain information on the spatial lattice
    # to be more flexible. Set the number of time slices here.
    lat.nt(NT)

    # Set up a random number generator.
    rng = isle.random.NumpyRNG(1075)

    # Set up a fresh HMC driver.
    # It handles all HMC evolution as well as I/O.
    # Last argument forbids the driver to overwrite any existing data.
    hmcState = isle.drivers.hmc.newRun(lat, PARAMS, rng, makeAction,
                                       OUTFILE, False)

    # Generate a random initial condition.
    # Note that configurations must be vectors of complex numbers.
    phi = isle.Vector(rng.normal(0,
                                 PARAMS.tilde("U", lat)**(1/2),
                                 lat.lattSize())
                      +0j)

    # Run thermalization.
    log.info("Thermalizing")
    # Pick an evolver which linearly decreases the number of MD steps from 20 to 5.
    # The number of steps (99) must be one less than the number of trajectories below.
    evolver = isle.evolver.LinearStepLeapfrog(hmcState.action, (1, 1), (20, 5), 99, rng)
    # Thermalize configuration for 100 trajectories without saving anything.
    evStage = hmcState(phi, evolver, 100, saveFreq=0, checkpointFreq=0)
    # Reset the internal counter so we start saving configs at index 0.
    hmcState.resetIndex()

    # Run production.
    log.info("Producing")
    # Pick a new evolver with a constant number of steps to get a reproducible ensemble.
    evolver = isle.evolver.ConstStepLeapfrog(hmcState.action, 1, 5, rng)
    # Produce configurations and save in intervals of 2 trajectories.
    # Place a checkpoint every 10 trajectories.
    hmcState(evStage, evolver, 100, saveFreq=2, checkpointFreq=10)
Example #2
0
def main():
    # Initialize Isle.
    # This sets up the command line interface, defines a barebones argument parser,
    # and parses and returns parsed arguments.
    # More complex parsers can be automatically defined or passed in manually.
    # See, e.g., `hmcThermalization.py` or `measure.py` examples.
    isle.initialize("default")

    # Set up a random number generator.
    rng = isle.random.NumpyRNG(1075)

    tune(rng)
    produce(rng)
def _init():
    """Initialize Isle."""

    # Define a custom command line argument parser.
    # Isle uses Python's argparse package and the following returns a new parser
    # which is set up to accept some default arguments like --version, --verbose, or --log.
    parser = isle.cli.makeDefaultParser(defaultLog="therm_example.log",
                                        description="Example script to thermalize a configuration")
    # Add custom arguments to control this script in particular.
    parser.add_argument("outfile", help="Output file", type=Path)
    parser.add_argument("-n", "--ntrajectories", type=int, metavar="N", required=True,
                        help="Generate N trajectories")
    parser.add_argument("-s", "--save-freq", type=int, metavar="SF", default=1,
                        help="Save every SF trajectories (default=1)")
    parser.add_argument("-c", "--checkpoint-freq", type=int, metavar="CF", default=None,
                        help="Write a checkpoint every CF trajectories (default=0)")
    parser.add_argument("--overwrite", action="store_true",
                        help="Overwrite existing output file.")

    # Initialize Isle and process arguments with the new parser.
    args = isle.initialize(parser)

    # If no checkpoint frequency is given, save a checkpoint for the last
    # configuration to make sure the run can be continued.
    if args.checkpoint_freq is None:
        # The number of saved configurations.
        nsaved = args.ntrajectories // args.save_freq
        # Place a checkpoint only for the last saved configuration.
        args.checkpoint_freq = nsaved * args.save_freq

    return args
Example #4
0
def main():
    # Initialize Isle.
    # Sets up the command line interface and parses arguments using the 'continue' parser.
    # This is the same parser that is used for the `isle continue` command that is
    # installed alongside Isle.
    args = isle.initialize("continue")

    # Set up an HMC driver based on the results of an existing run, loading
    # the action and all parameters.
    # This reads the indicated checkpoint (latest by default) from the file
    # and extracts the save and checkpoint frequencies based on how often data
    # was saved / checkpointed to the file before.
    hmcState, phi, evolver, \
        saveFreq, checkpointFreq = isle.drivers.hmc.continueRun(args.infile, args.outfile,
                                                                args.initial, args.overwrite)

    # If the used requested a particular save / checkpoint frequency,
    # use that instead of the ones read from file.
    if args.save_freq is not None:
        saveFreq = args.save_freq
    if args.checkpoint_freq is not None:
        checkpointFreq = args.checkpoint_freq

    # Build a new evolver.
    evolver = _buildEvolver(evolver, hmcState)

    # Run the driver with the input data and user specified parameters.
    getLogger(__name__).info("Starting evolution")
    hmcState(phi,
             evolver,
             args.ntrajectories,
             saveFreq=saveFreq,
             checkpointFreq=checkpointFreq)
Example #5
0
def main():
    # Initialize Isle.
    # This sets up the command line interface, defines an argument parser for a measurement
    # command, and parses and returns arguments.
    args = isle.initialize("meas", prog="measure")

    # Set up a measurement driver to run the measurements.
    measState = isle.drivers.meas.init(args.infile, args.outfile, args.overwrite)
    # The driver has retrieved all previously stored parameters from the input file,
    params = measState.params
    # as well as the lattice including the number of time slices nt.
    lat = measState.lattice

    # For simplicity do not allow the spin basis.
    assert params.basis == isle.action.HFABasis.PARTICLE_HOLE

    # Get "tilde" parameters (xTilde = x*beta/Nt) needed to construct measurements.
    muTilde = params.tilde("mu", lat)
    kappaTilde = params.tilde(measState.lattice.hopping(), lat.nt())

    # This object is a lower level interface for the Hubbard fermion action
    # needed by some measurements. The discretization (hopping) needs
    # to be selected manually.
    if params.hopping == isle.action.HFAHopping.DIA:
        hfm = isle.HubbardFermiMatrixDia(kappaTilde, muTilde, params.sigmaKappa)
    else:
        hfm = isle.HubbardFermiMatrixExp(kappaTilde, muTilde, params.sigmaKappa)

    # Define measurements to run.
    #
    # The measurements are run on each configuration in the slice passed to 'configSlice'.
    # It defaults to 'all configurations' in e.g. the Logdet measurement.
    # The two correlator measurements are called for every 10th configuration only
    # but across the entire range of configurations.
    #
    # The string parameter in each constructor call is the path in the output file
    # where the measurement shall be stored.
    # The driver ensures that the location can be written to and that nothing gets
    # overwritten by accident.
    measurements = [
        # log(det(M)) where M is the fermion matrix
        isle.meas.Logdet(hfm, "logdet"),
        # \sum_i phi_i
        isle.meas.TotalPhi("field"),
        # copy the action into the output file
        isle.meas.Action("action"),
        # single particle correlator for particles / spin up
        isle.meas.SingleParticleCorrelator(hfm, isle.Species.PARTICLE,
                                           "correlation_functions/single_particle",
                                           configSlice=s_[::10]),
        # single particle correlator for holes / spin down
        isle.meas.SingleParticleCorrelator(hfm, isle.Species.HOLE,
                                           "correlation_functions/single_hole",
                                           configSlice=s_[::10]),
    ]

    # Run the measurements on all configurations in the input file.
    # This automatically saves all results to the output file when done.
    measState(measurements)
Example #6
0
def main():
    parser = isle.cli.makeDefaultParser(description="Generate training datasets",
                                        defaultLog="none")
    parser.add_argument("--overwrite", action="store_true",
                        help="Overwrite existing output files.")
    clArgs = isle.initialize(parser)

    if not DATADIR.exists():
        DATADIR.mkdir()

    generate(clArgs.overwrite)
Example #7
0
def main():
    isle.initialize()
    np.random.seed(151)

    params = BASE_PARAMS.replace()
    phi = makePhi(LATTICE, params)
    fig = showGridOverview(LATTICE, params, phi, REF)

    if not DATA_DIR.exists():
        DATA_DIR.mkdir()

    while True:
        action, args = queryUser()
        if action == "quit":
            break

        if action == "redo":
            plt.close(fig)
            phi = makePhi(LATTICE, params)
            fig = showGridOverview(LATTICE, params, phi, REF)

        elif action == "save":
            save(LATTICE, params, phi, int(args[0]), REF)
def main():

    isle.initialize("default")
    log = getLogger("HMC")

    lattices = ["triangle-asymmetric"]  #, "triangle"]
    nts = [32]  #[128]#[64]#[16]
    discretizations = ["exponential", "diagonal"]

    for LATTICE, nt, discretization in product(lattices, nts, discretizations):

        log.info(f"{LATTICE} nt={nt} {discretization}")
        print(f"\n\n{LATTICE} nt={nt} {discretization}")

        lat = isle.LATTICES[LATTICE]
        lat.nt(nt)

        params = PARAMS(discretization)
        file = OUTFILE(LATTICE, nt, discretization)

        hmc(lat, params, file, log)
        measure(lat, params, file, log)
        bootstrap(lat, params, file, log)
        summary(lat, params, file, log)
Example #9
0
def main():
    # Initialize the command line interface on every MPI rank.
    # This clobbers up the output a little bit but saves us organizing this more.
    parser = isle.cli.makeDefaultParser(
        description="Tune integrator for multiple ensembles")
    parser.add_argument("--overwrite",
                        action="store_true",
                        help="Overwrite existing output file.")
    clArgs = isle.initialize(parser)

    with MPICommExecutor() as executor:
        if executor is not None:
            # This code runs only on the master rank.
            # Submit jobs for worker threads with all combinations of parameters.
            # There is no need to iterate through tasks in order as tuneForEnsemble does not
            # return anything, so use unordere=True to detect exceptions as early as possible below.
            results = executor.starmap(tuneForEnsemble,
                                       iterParams(clArgs),
                                       unordered=True)
            # Iterate through results to trigger any exceptions caught by the executor.
            for _ in results:
                pass
Example #10
0
def main():
    # Initialize Isle.
    # This sets up the command line interface, defines an argument parser for a measurement
    # command, and parses and returns arguments.
    args = isle.initialize("meas", prog="measure")

    # Set up a measurement driver to run the measurements.
    measState = isle.drivers.meas.init(args.infile, args.outfile,
                                       args.overwrite)
    # The driver has retrieved all previously stored parameters from the input file,
    params = measState.params
    # as well as the lattice including the number of time slices nt.
    lat = measState.lattice

    # For simplicity do not allow the spin basis.
    assert params.basis == isle.action.HFABasis.PARTICLE_HOLE

    # Get "tilde" parameters (xTilde = x*beta/Nt) needed to construct measurements.
    muTilde = params.tilde("mu", lat)
    kappaTilde = params.tilde(measState.lattice.hopping(), lat.nt())

    # This object is a lower level interface for the Hubbard fermion action
    # needed by some measurements. The discretization (hopping) needs
    # to be selected manually.
    if params.hopping == isle.action.HFAHopping.DIA:
        hfm = isle.HubbardFermiMatrixDia(kappaTilde, muTilde,
                                         params.sigmaKappa)
    else:
        hfm = isle.HubbardFermiMatrixExp(kappaTilde, muTilde,
                                         params.sigmaKappa)

    # Define measurements to run.
    species = (isle.Species.PARTICLE, isle.Species.HOLE)
    allToAll = {s: isle.meas.propagator.AllToAll(hfm, s) for s in species}

    _, diagonalize = np.linalg.eigh(isle.Matrix(hfm.kappaTilde()))

    #
    # The measurements are run on each configuration in the slice passed to 'configSlice'.
    # It defaults to 'all configurations' in e.g. the Logdet measurement.
    # The two correlator measurements are called for every 10th configuration only
    # but across the entire range of configurations.
    #
    # The string parameter in each constructor call is the path in the output file
    # where the measurement shall be stored.
    # The driver ensures that the location can be written to and that nothing gets
    # overwritten by accident.
    measurements = [
        # log(det(M)) where M is the fermion matrix
        isle.meas.Logdet(hfm, "logdet"),
        # \sum_i phi_i
        isle.meas.TotalPhi("field"),
        # collect all weights and store them in consolidated datasets instead of
        # spread out over many HDF5 groups
        isle.meas.CollectWeights("weights"),
        # polyakov loop
        isle.meas.Polyakov(params.basis,
                           lat.nt(),
                           "polyakov",
                           configSlice=s_[::10]),
        # one-point functions
        isle.meas.OnePointFunctions(allToAll[isle.Species.PARTICLE],
                                    allToAll[isle.Species.HOLE],
                                    "correlation_functions/one_point",
                                    configSlice=s_[::10],
                                    transform=diagonalize),
        # single particle correlator for particles / spin up
        isle.meas.SingleParticleCorrelator(
            allToAll[isle.Species.PARTICLE],
            "correlation_functions/single_particle",
            configSlice=s_[::10],
            transform=diagonalize),
        # single particle correlator for holes / spin down
        isle.meas.SingleParticleCorrelator(allToAll[isle.Species.HOLE],
                                           "correlation_functions/single_hole",
                                           configSlice=s_[::10],
                                           transform=diagonalize),
        isle.meas.SpinSpinCorrelator(allToAll[isle.Species.PARTICLE],
                                     allToAll[isle.Species.HOLE],
                                     "correlation_functions/spin_spin",
                                     configSlice=s_[::10],
                                     transform=diagonalize,
                                     sigmaKappa=params.sigmaKappa),
        isle.meas.DeterminantCorrelators(
            allToAll[isle.Species.PARTICLE],
            allToAll[isle.Species.HOLE],
            "correlation_functions/det",
            configSlice=s_[::10],
        )
    ]

    # Run the measurements on all configurations in the input file.
    # This automatically saves all results to the output file when done.
    measState(measurements)