Skip to content

Commit

Permalink
add feature gate for bond-atom spherical expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
liam-o-marsh committed Dec 11, 2023
1 parent e841798 commit 962651d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
28 changes: 28 additions & 0 deletions rascaline/src/calculators/bondatom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,31 @@ pub use spherical_expansion_bondcentered::{
SphericalExpansionForBonds,
SphericalExpansionForBondsParameters,
};



const FEATURE_GATE: &'static str = "RASCALINE_EXPERIMENTAL_BOND_ATOM_SPX";
fn get_feature_gate() -> bool {
use std::env;
if let Ok(var) = env::var(FEATURE_GATE) {
if var.len() == 0 {
false
} else {
let var = var.to_lowercase();
!(&var=="0" || var == "false" || var == "no" || var == "off")
}
} else {
false
}
}
fn assert_feature_gate() {
if !get_feature_gate() {
if !get_feature_gate() {
unimplemented!("Bond-Atom spherical expansion requires UNSTABLE feature gate: {}", FEATURE_GATE);
}
}
}
fn set_feature_gate() {
use std::env;
env::set_var(FEATURE_GATE, "true");
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::calculators::soap::{
use crate::systems::BATripletNeighborList;
use super::{canonical_vector_for_single_triplet,ExpansionContribution,RawSphericalExpansion,RawSphericalExpansionParameters};

use super::assert_feature_gate;

/// Parameters for spherical expansion calculator for bond-centered neighbor densities.
///
Expand Down Expand Up @@ -66,6 +67,7 @@ pub struct SphericalExpansionForBondsParameters {
impl SphericalExpansionForBondsParameters {
/// Validate all the parameters
pub fn validate(&self) -> Result<(), Error> {
assert_feature_gate();
self.cutoff_function.validate()?;
self.radial_scaling.validate()?;

Expand Down Expand Up @@ -340,6 +342,7 @@ impl CalculatorBase for SphericalExpansionForBonds {

#[time_graph::instrument(name = "SphericalExpansion::compute")]
fn compute(&mut self, systems: &mut [System], descriptor: &mut TensorMap) -> Result<(), Error> {
assert_feature_gate();
assert_eq!(descriptor.keys().names(), ["spherical_harmonics_l", "species_center_1", "species_center_2", "species_neighbor"]);
if descriptor.blocks().len() == 0 {
return Ok(());
Expand Down Expand Up @@ -515,6 +518,7 @@ mod tests {
use ndarray::ArrayD;
use metatensor::{Labels, TensorBlock, EmptyArray, LabelsBuilder, TensorMap};

use crate::calculators::bondatom::set_feature_gate;
use crate::systems::test_utils::test_systems;
use crate::{Calculator, CalculationOptions, LabelsSelection};
use crate::calculators::CalculatorBase;
Expand All @@ -525,6 +529,7 @@ mod tests {


fn parameters() -> SphericalExpansionForBondsParameters {
set_feature_gate();
SphericalExpansionForBondsParameters {
cutoffs: [3.5,3.5],
max_radial: 6,
Expand Down

0 comments on commit 962651d

Please sign in to comment.