Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: reusable bias #712

Open
HanatoK opened this issue Sep 9, 2024 · 1 comment
Open

Feature request: reusable bias #712

HanatoK opened this issue Sep 9, 2024 · 1 comment

Comments

@HanatoK
Copy link
Member

HanatoK commented Sep 9, 2024

It should be possible to use the bias energy, or other output components, of a colvarbias instance as the inputs of another colvarbias instance. For example, a histogram bias can reuse the bias energies from other biases to perform reweighting on-the-fly.

@giacomofiorin
Copy link
Member

As commented in #709 we have already several cases where we are running all biases in sequence:

colvars/src/colvarmodule.cpp

Lines 1016 to 1042 in a587282

if (proxy->check_smp_enabled() == COLVARS_OK && !biases_need_main_thread) {
if (use_scripted_forces && !scripting_after_biases) {
// calculate biases and scripted forces in parallel
error_code |= proxy->smp_biases_script_loop();
} else {
// calculate biases in parallel
error_code |= proxy->smp_biases_loop();
}
} else {
if (use_scripted_forces && !scripting_after_biases) {
error_code |= calc_scripted_forces();
}
// Straight loop over biases on a single thread
cvm::increase_depth();
for (bi = biases_active()->begin(); bi != biases_active()->end(); bi++) {
error_code |= (*bi)->update();
if (cvm::get_error()) {
cvm::decrease_depth();
return error_code;
}
}
cvm::decrease_depth();
}

So if there is a dependency like the one you describe, we could just do the same (until we have the AST that you proposed elsewhere).

The only tricky detail would be ensuring that the biases are listed internally in the same order as they were defined in the user input. colvarmodule::parse_biases() reads all biases of the same type at once, and goes alphabetically over bias types. However, we could record the position of each bias in a new input string and use that position to sort all newly added biases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants