Skip to content

Commit

Permalink
added export expression at any time
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnbr committed Oct 22, 2024
1 parent 7337c28 commit 87bf7d2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .zed/tasks.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"label": "Run Rust tests",
"command": "cargo test -p gammalooprs $env.ZED_SYMBOL --no-default-features --lib -- --nocapture",
"command": "cargo test -p gammalooprs $env.ZED_SYMBOL --no-default-features --lib -- --nocapture --exact",
"tags": ["rust-test"]
},
{
Expand Down
6 changes: 2 additions & 4 deletions python/gammaloop/interface/gammaloop_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,9 @@ def _update_config_chunk(self, root_path: str, config_chunk: dict[str, Any], upd
try:
value = eval(value)
except:
raise GammaLoopError(f"Invalid value for setting {
setting_path}. It is a string that needs to evaluate to a python dictionary:\n{pformat(updater)}")
raise GammaLoopError(f"Invalid value for setting {setting_path}. It is a string that needs to evaluate to a python dictionary:\n{pformat(updater)}")
if not isinstance(value, dict):
raise GammaLoopError(f"Invalid value for setting {
setting_path}. It is a string that needs to evaluate to a python dictionary:\n{pformat(updater)}")
raise GammaLoopError(f"Invalid value for setting {setting_path}. It is a string that needs to evaluate to a python dictionary:\n{pformat(updater)}")
else:
raise GammaLoopError(
f"Invalid value for setting {setting_path}. Default value of type '{type(config_chunk[key]).__name__}' is:\n{pformat(config_chunk[key])}\nand you supplied this value of type '{type(value).__name__}':\n{pformat(value)}")
Expand Down
26 changes: 13 additions & 13 deletions src/api/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
SerializableIntegrationState,
},
model::Model,
numerator::{AppliedFeynmanRule, PythonState, UnInit},
numerator::{Numerator, PythonState},
utils::F,
ExportSettings, HasIntegrand, Settings,
};
Expand Down Expand Up @@ -242,15 +242,14 @@ impl PythonWorker {
.map_err(|e| exceptions::PyException::new_err(e.to_string()))
.unwrap();
self.amplitudes.map_mut_graphs(|g| {
g.statefull_apply::<_, UnInit, AppliedFeynmanRule>(|d, b| {
d.map_numerator(|n| {
n.from_graph(
b,
export_settings.numerator_settings.global_prefactor.as_ref(),
)
})
})
.expect("could not apply Feynman rules")
let a = Numerator::default()
.from_graph(
&g.bare_graph,
export_settings.numerator_settings.global_prefactor.as_ref(),
)
.forget_type();

g.derived_data.as_mut().unwrap().numerator = a;
});
}

Expand Down Expand Up @@ -351,11 +350,12 @@ impl PythonWorker {
format: &str,
export_yaml_str: &str,
) -> PyResult<String> {
self.apply_feynman_rules(export_yaml_str);

let export_settings: ExportSettings = serde_yaml::from_str(export_yaml_str)
.map_err(|e| exceptions::PyException::new_err(e.to_string()))
.unwrap();
for amplitude in self.amplitudes.container.iter_mut() {
amplitude
.export_expressions(export_root, Self::printer_options(format))
.export_expressions(export_root, Self::printer_options(format), &export_settings)
.map_err(|e| exceptions::PyException::new_err(e.to_string()))?;
}
Ok("Exported expressions".to_string())
Expand Down
15 changes: 8 additions & 7 deletions src/cross_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::graph::{BareGraph, Graph, SerializableGraph};
use crate::model::{Model, Particle};
use crate::momentum::Signature;
use crate::numerator::{
AppliedFeynmanRule, ContractionSettings, Evaluators, GetSingleAtom, NumeratorState,
AppliedFeynmanRule, ContractionSettings, Evaluators, GetSingleAtom, Numerator, NumeratorState,
PythonState, TypedNumeratorState, UnInit,
};
use crate::{utils::*, ExportSettings, Externals, Polarizations, Settings};
Expand Down Expand Up @@ -918,20 +918,21 @@ impl<S: GetSingleAtom + NumeratorState> Amplitude<S> {
&self,
export_root: &str,
printer_ops: PrintOptions,
export_settings: &ExportSettings,
) -> Result<(), Report> {
let path = Path::new(export_root)
.join("sources")
.join("amplitudes")
.join(self.name.as_str())
.join("expressions");
for amplitude_graph in self.amplitude_graphs.iter() {
let num = &amplitude_graph
.graph
.derived_data
.as_ref()
.unwrap()
.numerator
let num = Numerator::default()
.from_graph(
&amplitude_graph.graph.bare_graph,
export_settings.numerator_settings.global_prefactor.as_ref(),
)
.get_single_atom();

let dens: Vec<(String, String)> = amplitude_graph
.graph
.bare_graph
Expand Down
10 changes: 2 additions & 8 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,20 +573,17 @@ impl Edge {
match self.edge_type {
EdgeType::Incoming => {
let [lorentz, spin, color] = in_slots.dual().kroneker(&out_slots);
println!("Incoming color: {}", color);

[lorentz * spin, color]
}
EdgeType::Outgoing => {
let [lorentz, spin, color] = out_slots.dual().kroneker(&in_slots);
// println!("Outgoing color: {}", color);
println!("Outgoing color: {}", color);

[lorentz * spin, color]
}
EdgeType::Virtual => {
let mut atom = self.propagator.numerator.clone();

println!("in prop:{atom}");

let pfun = Pattern::parse("P(x_)").unwrap();
if self.particle.is_antiparticle() {
atom = pfun.replace_all(
Expand Down Expand Up @@ -667,9 +664,6 @@ impl Edge {
color_atom.replace_all_multiple(&reps),
];

println!("out prop:{}", out[0]);
println!("out color:{}", out[1]);

out
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/numerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,12 +1413,12 @@ impl GammaSimplified {
while let Some(a) = it.next() {
for (_, v) in a.match_stack {
match v {
Match::Single(s) => {
Match::Single(_) => {
if max_nargs < 1 {
max_nargs = 1;
}
}
Match::Multiple(s, v) => {
Match::Multiple(_, v) => {
if max_nargs < v.len() {
max_nargs = v.len();
}
Expand Down

0 comments on commit 87bf7d2

Please sign in to comment.