Skip to content

Commit

Permalink
fix(rust): ⬆️ update symbolica and spenso
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnbr committed Aug 16, 2024
1 parent 49c46e3 commit 4004db2
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 73 deletions.
100 changes: 55 additions & 45 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@ similar.opt-level = 3
[patch.crates-io]
symbolica = { path = "./python/gammaloop/dependencies/symbolica" }
spenso = { git = "https://github.com/alphal00p/spenso", branch = "master" }
# spenso = { path = "../spenso" }
# spenso = { path = "../../alphal00p/spenso" }
2 changes: 1 addition & 1 deletion benches/cff_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn load_helper(path: &str, use_orientations: bool) -> Graph {

let export_settings = ExportSettings {
compile_cff: !use_orientations,
cpe_rounds_cff: 1,
cpe_rounds_cff: Some(1),
compile_separate_orientations: use_orientations,
gammaloop_compile_options: GammaloopCompileOptions {
inline_asm: env::var("USE_ASM").is_ok(),
Expand Down
22 changes: 8 additions & 14 deletions src/cff/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,23 +485,21 @@ impl CFFExpression {
let atom = self.construct_atom_for_term(term_id, None);
let atom_view = atom.as_view();

let mut tree = atom_view
.to_eval_tree(|r| r.clone(), &function_map, params)
.unwrap();
let mut tree = atom_view.to_evaluation_tree(&function_map, params).unwrap();

tree.horner_scheme();
tree.common_subexpression_elimination(1);
tree.common_subexpression_elimination();

let tree_ft = tree.map_coeff::<F<T>, _>(&|r| r.into());
tree_ft.linearize(1)
tree_ft.linearize(Some(1))
})
.collect()
}

pub fn build_joint_symbolica_evaluator<T: FloatLike + Default>(
&self,
params: &[Atom],
cpe_rounds: usize,
cpe_rounds: Option<usize>,
) -> ExpressionEvaluator<F<T>> {
let orientation_atoms = self
.orientations
Expand All @@ -512,16 +510,12 @@ impl CFFExpression {
let orientation_atom_views = orientation_atoms.iter().map(Atom::as_view).collect_vec();
let function_map = FunctionMap::new();

let mut tree: EvalTree<Rational> = AtomView::to_eval_tree_multiple(
&orientation_atom_views,
|r| r.clone(),
&function_map,
params,
)
.unwrap();
let mut tree: EvalTree<Rational> =
AtomView::to_eval_tree_multiple(&orientation_atom_views, &function_map, params)
.unwrap();

tree.horner_scheme();
tree.common_subexpression_elimination(1);
tree.common_subexpression_elimination();

let tree_ft = tree.map_coeff::<F<T>, _>(&|r| r.into());
tree_ft.linearize(cpe_rounds)
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ pub struct SubtractionSettings {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExportSettings {
pub compile_cff: bool,
pub cpe_rounds_cff: usize,
pub cpe_rounds_cff: Option<usize>,
pub compile_separate_orientations: bool,
pub gammaloop_compile_options: GammaloopCompileOptions,
}
Expand Down
16 changes: 8 additions & 8 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,17 +992,17 @@ impl Model {
if let Some(value) = cpl.value {
let rhs = if value.im == 0.0 {
let name = Atom::new_var(State::get_symbol(format!("{}_re", cpl.name)));
fn_map.add_constant(name.clone().into(), Rational::from(value.re));
fn_map.add_constant(name.clone(), Rational::from(value.re));
name.into_pattern()
} else if value.re == 0.0 {
let name = Atom::new_var(State::get_symbol(format!("{}_im", cpl.name)));
fn_map.add_constant(name.clone().into(), Rational::from(value.im));
fn_map.add_constant(name.clone(), Rational::from(value.im));
name.into_pattern()
} else {
let name_re = Atom::new_var(State::get_symbol(cpl.name.clone() + "_re"));
fn_map.add_constant(name_re.clone().into(), Rational::from(value.re));
fn_map.add_constant(name_re.clone(), Rational::from(value.re));
let name_im = Atom::new_var(State::get_symbol(cpl.name.clone() + "_im"));
fn_map.add_constant(name_im.clone().into(), Rational::from(value.im));
fn_map.add_constant(name_im.clone(), Rational::from(value.im));
let i = Atom::new_var(State::I);
(&name_re + i * &name_im).into_pattern()
};
Expand Down Expand Up @@ -1033,22 +1033,22 @@ impl Model {
if value.re.is_zero() {
let name =
Atom::new_var(State::get_symbol(format!("{}_im", param.name)));
fn_map.add_constant(name.clone().into(), Rational::from(value.im.0));
fn_map.add_constant(name.clone(), Rational::from(value.im.0));
name.into_pattern()
} else {
let name_re =
Atom::new_var(State::get_symbol(param.name.clone() + "_re"));
fn_map.add_constant(name_re.clone().into(), Rational::from(value.re.0));
fn_map.add_constant(name_re.clone(), Rational::from(value.re.0));
let name_im =
Atom::new_var(State::get_symbol(param.name.clone() + "_im"));
fn_map.add_constant(name_im.clone().into(), Rational::from(value.im.0));
fn_map.add_constant(name_im.clone(), Rational::from(value.im.0));
let i = Atom::new_var(State::I);
(&name_re + i * &name_im).into_pattern()
}
}
ParameterType::Real => {
let name = Atom::new_var(State::get_symbol(format!("{}_re", param.name)));
fn_map.add_constant(name.clone().into(), Rational::from(value.re.0));
fn_map.add_constant(name.clone(), Rational::from(value.re.0));
name.into_pattern()
}
};
Expand Down
Loading

0 comments on commit 4004db2

Please sign in to comment.