--- myst: html_meta: "description": "Guide to coarse-graining methods in eOn, such as MCAMC and AS-KMC, for accelerating simulations with vastly different timescales." "keywords": "eOn coarse graining, MCAMC, AS-KMC, superbasins, accelerated simulation" --- # Coarse graining In aKMC simulations where there are vastly different rates, the simulation can get stuck in a group of states connected by relatively fast rates. Exploring slower transitions can take a prohibitively large number of KMC steps. `eOn` implements two methods that skip those fast recrossings. ```{note} AS-KMC and MCAMC cannot be used simultaneously. ``` ## Monte Carlo with Absorbing Markov Chains (MCAMC) The first method, projective dynamics, described in {cite:t}`cg-novotnyTutorialAdvancedDynamic2001`, groups states that are joined by fast rates into "superbasins". Information about transitions between states in a superbasin is lost, but the rates for transitions across a superbasin are correct. The numpy fallback copies the rate matrices and the cost vector, as the compiled solver does, so a later call sees the same input. Transition counts and energy levels are replaced in one step. A write that stops partway leaves the previous file. A superbasin directory that already exists still gets a `storage` folder. A later merge archives the previous basin there. ## Accelerated Superbasin Kinetic Monte Carlo (AS-KMC) The second method, accelerated superbasin kinetic Monte Carlo (AS-KMC) of {cite:t}`cg-voterHyperdynamicsAcceleratedMolecular1997`, artificially raises low barriers. The dynamics between states connected by fast rates are simulated, but an error is introduced in the dynamics direction and time. The basic process of AS-KMC involves gradually raising process barriers found to be inside of a superbasin such that exiting from the basin gradually becomes more likely. The method is designed to raise all the barriers in the superbasin simultaneously. Once a particular barrier has been crossed a certain number of times, {math}`N_f` (more on determining {math}`N_f` shortly), a check is performed to determine whether or not the current state is part of a superbasin. The first time a process is followed, that sighting counts toward {math}`N_f`. When the count already meets {math}`N_f`, the Superbasin Criterion runs on that visit. This is called the Superbasin Criterion. In the Superbasin Criterion, a search is performed, originating at the current state and proceeding outward through all low-barrier processes to adjacent states, and then through all low-barrier processes from each of these states, etc. For each low-barrier process found, if the process has been followed fewer than {math}`N_f` times, the Superbasin Criterion fails and no barriers are raised. Thus, in the outward-expanding search from the originating state, the search continues until either a low-barrier process has been seen fewer than {math}`N_f` times (and the Criterion fails) or until all connected low-barrier processes have been found and have been crossed at least {math}`N_f` times (the edges of the superbasin are then defined and the Criterion passes). If the Superbasin Criterion passes, all the low-barrier processes (each of which as been crossed {math}`N_f` times) are raised. Several parameters dictate the functioning of the AS-KMC method. These parameters dictate how much the barriers are raised each time the Superbasin Criterion passes({any}`eon.schema.CoarseGrainingConfig.askmc_barrier_raise_param`), what defines a "low-barrier" for use in the Superbasin Criterion({any}`eon.schema.CoarseGrainingConfig.askmc_high_barrier_def`), and the approximate amount of error the user might expect in eventual superbasin exit direction and time compared to normal KMC simulation ({any}`eon.schema.CoarseGrainingConfig.askmc_confidence`). A new modified-process row is appended as one line, then flushed and synced. A final line with no newline or the wrong number of fields is dropped, and the next append cuts that tail off first. A write that stops partway leaves the previous rows. The counters in `askmc_data.txt` are replaced in one step. A write that stops partway leaves the previous counters. ## amsel discover_decide `[amsel] discover_decide = true` runs on the current state's process table. The state list can hold one state. `use_mcamc` stays off. `use_mcamc` is not required. The repeat-count confidence scheme does not hold this step. A run that leaves `discover_decide` off still waits for `confidence` under `confidence_scheme`. A barrier strictly below `e_min_init` counts as an in-basin edge. A barrier at or above `e_min_init` counts as an exit. On Si6N8 isomer 1 the back barrier is 0.20 eV and the flip-out barrier is 0.30 eV. With `e_min_init` at 0.25 eV the 0.20 eV edge stays in the basin and the 0.30 eV edge leaves. A table that has only the 0.30 eV saddle, and no faster edge, still leaves. The transient set is that state. The product is absorbing. A product column of -1 is that same exit: the label sent to amsel is a 32-bit id at or above 2147483648, and the hop creates the product state from the process id. The basin comes from `amsel.discover_decide_status` when a faster edge is present. The exit time and the exit channel come from the mean-rate method (MRM) or from first-passage-time analysis (FPTA). `debug_use_mean_time` selects MRM. The mean exit time is the MRM value `tau_total`. Otherwise, FPTA draws one first-passage time. Both kernels live in the `amsel` package. With that package absent, the log line reads `amsel discover_decide status=unavailable` and no step is taken until the confidence threshold is met. Once that threshold is met, the step is ordinary kinetic Monte Carlo. ```{code-block} ini [amsel] discover_decide = true e_min_init = 0.25 e_min_step = 0.05 e_min_floor = 0.05 cv_threshold = 10.0 on_error = fallback_single ``` One status list: - `unavailable`, `available` off: `amsel` did not import, or `on_error` is `unavailable_mcamc` after a failed call - `fallback_single`, `available` on: the call failed and `on_error` is `fallback_single`; the step stays ordinary kinetic Monte Carlo - `accepted` or `retightened`: one basin, and the exit comes from MRM or FPTA - `split_required`: the exit is the primary basin that contains the entry state - `rejected_no_metastable_basin`: no basin, and the step stays ordinary kinetic Monte Carlo `unavailable` together with `available` on sits outside this list. ```{eval-rst} .. autopydantic_model:: eon.schema.AmselConfig ``` With `use_mcamc` on as well, an accepted basin still leaves through MRM or FPTA. A rejected basin falls through to the MCAMC superbasin step. `split_required` on that MCAMC object keeps the entry state and writes the reduced member list. The superbasin exit draw uses the same strict cumulative test as a single-state kinetic Monte Carlo step. A column whose probability is zero is not selected when the draw is zero. ## Configuration ```{code-block} ini [Coarse Graining] ``` ```{eval-rst} .. autopydantic_model:: eon.schema.CoarseGrainingConfig ``` ## References ```{bibliography} --- style: alpha filter: docname in docnames labelprefix: CG_ keyprefix: cg- --- ``` ## amsel state confidence `[AKMC] confidence_scheme = amsel` takes the confidence of a state from the `amsel` package. `[amsel] state_confidence` selects the score: - `heuristic` rises with the number of processes - `good-turing` is one minus singletons over hits - `reverse-capped` bounds the heuristic by the exit rate the state's own searches found over that rate plus the rate known only from the far side - `two-sided` is the share of saddles known from the far side that the searches recover, pooled over all states, with the same bound ```{code-block} ini [AKMC] confidence_scheme = amsel [amsel] state_confidence = two-sided reverse_barrier_tolerance = 0.02 ``` Only a saddle search that was launched from a state and came back counts as a find of that state. When the trajectory enters a state, the reverse of the entry process is in its table and counts as known from the far side, not as a find. A state none of whose searches has found a process has confidence 0 for every score. ### The coverage score `state_confidence = coverage` is for `displacement = direction_cover`, and it is the score the search loop below is built for. It uses none of the four scores above. `amsel` rebuilds the direction cover of the state from its search records and returns one minus the posterior probability that a missed exit carries more than `relevant_rate_share` of the state's escape rate. That probability comes from how much of the cover of each active atom the searches have tried, what they found there, and at what rates. The state is as confident as its least covered atom. ```{code-block} ini [AKMC] confidence_scheme = amsel confidence = 0.95 [amsel] displacement = direction_cover state_confidence = coverage relevant_rate_share = 0.01 category_alpha = 0.5 ``` Under this score `[AKMC] confidence` is a probability. `0.95` searches a state until a relevant missed exit has posterior probability at most 0.05. A value chosen for one of eOn's own schemes does not carry over: those are functions of repeat counts and are not probabilities. `relevant_rate_share` and `category_alpha` default to the values `amsel` uses, a share of 0.01 and Jeffreys' prior of 1/2; a smaller share asks for more searches. A state with no search scores close to 0 from the estimator itself, and no other state enters the score, so the first state of a run is not a special case. A state with no free active atom has no cover; it is searched with the eOn displacement and scored with eOn's `new` scheme. The log has one line per change of the records, `amsel coverage: state N confidence ...`, with the worst and the mean missed-exit probability over the active atoms. The run searches the state it is in until the score meets `[AKMC] confidence` and then leaves, so each state it left was certified when it was left. After every pass the log reports the residence weight of the states that are not certified, `amsel residence share (reported, not enforced): eta_res=...`: the share of the mean time to leave the visited network, from the first state, that is spent in them. A process whose product was never entered counts as a way out of the network. The number is a record of how much of the mean time rests on unfinished tables. Nothing acts on it: the run does not return to a state because of it. With `discover_decide` on, an amsel exit is taken as soon as one process leaves the basin, even when the state is not confident. Set `discover_wait_for_confidence = true` to search until `[AKMC] confidence` is met and take the exit from that table. ## amsel search starts `[amsel] displacement = direction_cover` takes every saddle-search start of an AKMC state from `amsel`: `active_atoms` selects the atoms, and the direction cover of the state gives the next start. Recycling and the kinetic database still come first. The `[Saddle Search]` displacement weights are then not used. A start is an arm of the cover, a centre atom and a direction on it. `amsel` plans it from the state's search records: it rebuilds the cover from what every earlier search of the state ended on and returns its best free arm, so the directions tried on an atom spread away from the ones already tried and toward the gaps the results leave. The push is the seed of the arm, which moves the centre atom along the direction and its neighbours with it, scaled so that the whole displacement has length `displace_magnitude`. The client begins a search at the start it is sent only when `[Saddle Search] client_displace_type` is `load`; with any other value it draws a displacement of its own. Every job with an amsel start is therefore sent with `client_displace_type = load`, and a `config.ini` that sets another value next to `direction_cover` is rejected when it is read. Leave the key out or set it to `load`. A state with no free active atom takes the `[Saddle Search]` displacement instead. A cell without a defect is one, such as the crystal a vacancy and an interstitial leave when they recombine. The log then has a line `amsel direction_cover: state N uses the eOn displacement from here on`, the reason is a record of kind `fallback` in the state's search records, and the searches of that state have type `random` in `search_results.txt`. So does a state whose cover has no arm left: every arm is recorded or out. Repeating arms would count the same finds again. Every start and what its search ended on are kept as records of a readcon-db corpus in the state directory, `states/N/searches.db`. A search is two trajectories of one frame: `2 * wuid` is written when the job is created and `2 * wuid + 1` when its result is registered. A start with no second trajectory has not come back. The fields of a record are under `eon_search` in the metadata of its frame. A record holds no second copy of a structure eOn keeps. The frame of a start holds the atoms its push moves, and the record the push as it was applied: `mode` lists each of those atoms with its unit vector, `magnitude` the length, `atoms` their rows in the state, written so that the numbers read back unchanged. The structure the client was sent is the reactant plus that push. The frame of a result holds the active atoms of the structure the search ended on. A search that landed on a process names it by `process_id`; its saddle and far minimum are in `states/N/procdata`. A search that landed on no process leaves no file in eOn unless `[Debug] keep_bad_saddles` is set, and its record then names the directory. A search of a 4000-atom state costs about 10 kB on disk. A search can find a connected saddle that eOn leaves off the table, as it does above the thermal window. Its record is `connected` with `off_table` set, the barrier and the energies, no process and no rate: the direction led to a saddle, and the saddle is no exit of the table. eOn keeps no file of it, so the active atoms of the saddle and of the far minimum are the two frames of that record. The next start is planned from this corpus and from nothing else, so a start is used when its search is created: a search that fails or is lost is not tried again. The records are read in work-unit order, so the plan does not depend on the order in which several clients return. The corpus is an LMDB directory. It follows `[Paths] states`, and LMDB does not support network filesystems: put the state directory on a local disk when the run directory is not. One corpus is opened per state, each with a lock file, and at most eight are open at a time. A server that stops between recording a start and submitting its job finds the record when it starts again and sends that start; it does not plan a second one for the same work unit. A server that stops between registering a result and recording it leaves the start without a result: its arm stays taken, and the coverage score counts it as not returned. A start with no second trajectory has not come back. The next start is planned from this corpus and from nothing else, so a start is used when its search is created: a search that fails or is lost is not tried again. The records are read in work-unit order, so the plan does not depend on the order in which several clients return. The corpus needs the `readcon_db` module. `direction_cover` is rejected when the configuration is read if the module does not load, and it is rejected with `[AKMC] server_side_process_search = true`, which keeps no records. ```{code-block} ini [amsel] displacement = direction_cover active_atoms = decaf_clustering ``` `amsel` has to be built with the `direction-cover` feature.