Skip to content

Commit

Permalink
Merge pull request #10 from alphal00p/integrand
Browse files Browse the repository at this point in the history
Merge integrand into main
  • Loading branch information
GraDje13 authored Mar 27, 2024
2 parents 3c73fb5 + a8f1af6 commit c9aac0d
Show file tree
Hide file tree
Showing 48 changed files with 7,471 additions and 809 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ Cargo.lock

poetry.lock

# Target directory of rust tests
rust_test_binaries

# These are backup files generated by rustfmt
**/*.rs.bk

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ funty = "2.0.0"
block-id = "0.2.1"
once_cell = "1.19.0"
enum_delegate = { git = "https://gitlab.com/dawn_app/enum_delegate" }
ctrlc = "3.4.4"

[dependencies.pyo3]
features = ["multiple-pymethods"]
Expand Down
1 change: 1 addition & 0 deletions benches/evaluate_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ fn const_map_gen<'a, 'b, I>(
'a: 'b,
I: TensorStructure + Clone + Debug,
{
#[allow(clippy::unused_enumerate_index)]
for (_i, p) in params.iter().enumerate() {
let pdata = test_tensor(p.structure().clone()).to_dense();
p.try_as_symbolic()
Expand Down
1 change: 1 addition & 0 deletions examples/rust/tensors/evaluate_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ fn const_map_gen<'a, 'b, I>(
'a: 'b,
I: TensorStructure + Clone + Debug,
{
#[allow(clippy::unused_enumerate_index)]
for (_i, p) in params.iter().enumerate() {
let pdata = test_tensor(p.structure().clone()).to_dense();
p.try_as_symbolic()
Expand Down
5 changes: 5 additions & 0 deletions python/gammaloop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,13 @@ def cli():
default=False, help='Show gammaloop Python venv activate path')
argparser.add_argument('--command', '-c', dest='run_command', action='store_true',
default=False, help='Directly run command specified')
argparser.add_argument('--logging_format', '-lf', dest='logging_format', default='long',
choices=['long', 'short', 'min', 'none'], help='Type of prefix for the logging format')
args = argparser.parse_args()

from . import misc
misc.LOGGING_PREFIX_FORMAT = args.logging_format

if args.show_venv_activate_path:
venv_path = os.path.abspath(os.path.join(
GL_PATH, 'dependencies', 'venv', 'bin', 'activate'))
Expand Down
18 changes: 18 additions & 0 deletions python/gammaloop/_gammaloop.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,21 @@ class Worker:

def inspect_integrand(self, integrand: str, pt: list[float], term: list[int], force_radius: bool, is_momentum_space: bool, use_f128: bool) -> None:
""" Inspects the integrand given in argument at the point given in argument. """

def integrate_integrand(self, integrand: str, num_cores: int, result_path: str, workspace_path: str, target: tuple[float, float] | None) -> None:
""" Integrates the integrand given in argument over the target given in argument. """

def load_master_node(self, integrand: str) -> None:
"""Setup a master node for the integrand given in argument."""

def write_batch_input(self, num_cores: int, num_samples: int, export_grid: bool, output_accumulator: bool, workspace_path: str, job_id: int) -> None:
""" Writes a batch input file for a integration job """

def process_batch_output(self, workspace_path: str, job_id: int) -> None:
"""process the output of a job"""

def display_master_node_status(self) -> None:
"""display information about the current run"""

def update_iter(self) -> None:
"""finish the iteration"""
7 changes: 5 additions & 2 deletions python/gammaloop/cross_section/supergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,13 @@ def to_serializable_dict(self) -> dict[str, Any]:


class AmplitudeGraph(object):
def __init__(self, sg_id: int, sg_cut_id: int, fs_cut_id: int, amplitude_side: Side, graph: Graph):
def __init__(self, sg_id: int, sg_cut_id: int, fs_cut_id: int, amplitude_side: Side, graph: Graph, multi_channeling_structure: list[int] = []):
self.sg_id: int = sg_id
self.sg_cut_id: int = sg_cut_id
self.fs_cut_id: int = fs_cut_id
self.amplitude_side: Side = amplitude_side
self.graph: Graph = graph
self.multi_channeling_channels: list[int] = []

def draw(self, model: Model, drawings_path: str, file_name: str | None, **drawing_options: dict[str, Any]) -> Path:

Expand All @@ -160,7 +161,8 @@ def from_serializable_dict(model: Model, amplitude_graph_dict: dict[str, Any]) -
amplitude_graph_dict['sg_cut_id'],
amplitude_graph_dict['fs_cut_id'],
Side[amplitude_graph_dict['amplitude_side']],
Graph.from_serializable_dict(model, amplitude_graph_dict['graph'])
Graph.from_serializable_dict(model, amplitude_graph_dict['graph']),
amplitude_graph_dict['multi_channeling_channels']
)

def to_serializable_dict(self) -> dict[str, Any]:
Expand All @@ -170,4 +172,5 @@ def to_serializable_dict(self) -> dict[str, Any]:
'fs_cut_id': self.fs_cut_id,
'amplitude_side': str(self.amplitude_side),
'graph': self.graph.to_serializable_dict(),
'multi_channeling_channels': self.multi_channeling_channels,
}
6 changes: 3 additions & 3 deletions python/gammaloop/data/run_cards/cmd.gL
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#import_graphs ./python/gammaloop/tests/test_data/qgraf_outputs/epem_a_ddx_NLO.py --format=qgraph
import_model scalars-full
#export_model ./scalars.yaml
#import_graphs ./python/gammaloop/tests/test_data/qgraf_outputs/massless_triangle.py --format=qgraph
import_graphs ./python/gammaloop/tests/test_data/qgraf_outputs/massless_triangle.py --format=qgraph
#import_graphs ./python/gammaloop/tests/test_data/qgraf_outputs/bubble.py --format=qgraph
#import_graphs ./python/gammaloop/tests/test_data/qgraf_outputs/massless_box.py --format=qgraph
#import_graphs ./python/gammaloop/tests/test_data/qgraf_outputs/fishnet_2x3.py --format=qgraph
#import_graphs ./python/gammaloop/tests/test_data/qgraf_outputs/cube.py --format=qgraph
#import_graphs ./python/gammaloop/tests/test_data/qgraf_outputs/fishnet_2x2.py --format=qgraph
#import_graphs ./python/gammaloop/tests/test_data/qgraf_outputs/sunrise.py --format=qgraph
#import_graphs ./python/gammaloop/tests/test_data/qgraf_outputs/double_triangle.py --format=qgraph
import_graphs ./python/gammaloop/tests/test_data/qgraf_outputs/mercedes.py --format=qgraph
#import_graphs ./python/gammaloop/tests/test_data/qgraf_outputs/mercedes.py --format=qgraph
#import_graphs ./python/gammaloop/tests/test_data/qgraf_outputs/triangle_box.py --format=qgraph
#import_graphs ./python/gammaloop/tests/test_data/qgraf_outputs/isopod.py --format=qgraph
set drawing.feynmp.show_edge_composite_momenta True
Expand All @@ -26,4 +26,4 @@ show_settings drawing.feynmp.show_edge_composite_momenta
output TEST_OUTPUT
launch TEST_OUTPUT
info
inspect mercedes -p 0.123 0.3242 0.4233 0.14235 0.25122 0.3245 0.12337 0.224237 0.32327 -t 0
integrate massless_triangle -c 1
51 changes: 25 additions & 26 deletions python/gammaloop/data/run_cards/rust_run_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,46 @@ Integrand:
type: gamma_loop
Kinematics:
e_cm: 3.0
externals: !constant
- - 2.0
- 2.0
- 3.0
- 4.0
- - 1.0
- 2.0
- 9.0
- 3.0
externals:
type: constant
momenta:
- - 2.0
- 2.0
- 3.0
- 4.0
- - 1.0
- 2.0
- 9.0
- 3.0
Parameterization:
mode: spherical
mapping: linear
b: 1.0
b: 10.0
Integrator:
n_bins: 0
n_bins: 16
bin_number_evolution: null
min_samples_for_update: 0
n_start: 0
min_samples_for_update: 100
n_start: 1000000
n_increase: 0
n_max: 0
n_max: 1000000000
integrated_phase: real
learning_rate: 0.0
learning_rate: 1.5
train_on_avg: false
show_max_wgt_info: false
max_prob_ratio: 0.0
max_prob_ratio: 0.01
seed: 0
Observables: []
Selectors: []
Stability:
rotation_axis: x
levels:
- precision: Double
required_precision_for_re: 1e-15
required_precision_for_im: 1e-15
required_precision_for_re: 1e-5
required_precision_for_im: 1e-5
escalate_for_large_weight_threshold: 0.9
accepted_radius_in_x_range:
- 0.0
- 0.9
- precision: Quad
required_precision_for_re: 1e-15
required_precision_for_im: 1e-15
required_precision_for_re: 1e-5
required_precision_for_im: 1e-5
escalate_for_large_weight_threshold: -1.0
accepted_radius_in_x_range:
- 0.0
- 1.0
sampling:
type: default
103 changes: 99 additions & 4 deletions python/gammaloop/interface/gammaloop_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Any
from pprint import pformat
import yaml
import shutil
from gammaloop.misc.common import GammaLoopError, logger, Side, pjoin, load_configuration, GAMMALOOP_CONFIG_PATHS, gl_is_symbolica_registered, GL_PATH
from gammaloop.misc.utils import Colour
from gammaloop.base_objects.model import Model, InputParamCard
Expand All @@ -32,6 +33,7 @@
'info',
'integrate',
'inspect',
'hpc_run',
'test_ir_limits',
'test_uv_limits',
'set'
Expand Down Expand Up @@ -714,32 +716,59 @@ def do_inspect(self, str_args: str) -> None:
if str_args == 'help':
self.inspect_parser.print_help()
return
_args = self.inspect_parser.parse_args(split_str_args(str_args))
args = self.inspect_parser.parse_args(split_str_args(str_args))

if self.launched_output is None:
raise GammaLoopError(
"No output launched. Please launch an output first with 'launch' command.")

args = self.inspect_parser.parse_args(split_str_args(str_args))
self.rust_worker.inspect_integrand(
args.integrand, args.point, args.term, args.force_radius, args.is_momentum_space, args.use_f128)

# raise GammaLoopError("Command not implemented yet")

# integrate command
integrate_parser = ArgumentParser(prog='integrate')
integrate_parser.add_argument(
"integrand", type=str, help="Integrand to integrate.")
integrate_parser.add_argument('--cores', '-c', type=int, default=1,)
integrate_parser.add_argument(
'--target', '-t', nargs=2, type=float, default=None)
integrate_parser.add_argument(
'--restart', '-r', action='store_true',)

def do_integrate(self, str_args: str) -> None:
if str_args == 'help':
self.integrate_parser.print_help()
return
_args = self.integrate_parser.parse_args(split_str_args(str_args))
args = self.integrate_parser.parse_args(split_str_args(str_args))

if self.launched_output is None:
raise GammaLoopError(
"No output launched. Please launch an output first with 'launch' command.")

raise GammaLoopError("Command not implemented yet")
target = None
if args.target is not None:
target = (args.target[0], args.target[1])

result_output_path = self.launched_output.joinpath(
"runs").joinpath("run.yaml")

workspace_path = self.launched_output.joinpath("workspace")
if args.restart and os.path.exists(workspace_path):
shutil.rmtree(workspace_path)

if not os.path.exists(workspace_path):
os.mkdir(workspace_path)

self.rust_worker.integrate_integrand(
args.integrand, args.cores, str(result_output_path), str(workspace_path), target)

# nuke the workspace if integration finishes
# For now leave the possibility of restarting where integration left off.
# Maybe in the future add an option to automatically clean the workspace after running is completed or
# specify a "run_tag" that allows to have mutliple workspace concurrently active
# shutil.rmtree(workspace_path)

# test_ir_limits
test_ir_limits_parser = ArgumentParser(prog='test_ir_limits')
Expand Down Expand Up @@ -788,3 +817,69 @@ def do_help(self, str_args: str) -> None:

args = self.help_parser.parse_args(split_str_args(str_args))
self.run(CommandList.from_string(f"{args.cmd} help"))

hpc_parser = ArgumentParser(prog='hpc_run')
hpc_parser.add_argument('integrand', type=str,
help="Integrand to integrate", default=None)

def do_hpc_run(self, str_args: str) -> None:
args = self.hpc_parser.parse_args(split_str_args(str_args))
if self.launched_output is None:
raise GammaLoopError(
"No output launched. Please launch an output first with 'launch' command.")

# create a workspace for batch input/output files
workspace_path = self.launched_output.joinpath("workspace")

if not workspace_path.exists():
workspace_path.mkdir()

from hyperqueue import LocalCluster, Job # type: ignore
from hyperqueue.cluster import WorkerConfig # type: ignore

print("starting hpc test run")
self.rust_worker.load_master_node(args.integrand)

# this will be loaded from settings, eventually with dynamic points that can increase with iterations
n_iterations = 10
n_tasks = 4
n_points_per_task = 1000000
n_cores = 1

export_grid = False
output_accumulator = False

# this local cluster is just for testing
with LocalCluster() as cluster:
cluster.start_worker()

client = cluster.client() # type: ignore

for _ in range(n_iterations):
task_ids = [i*(n_iterations + 1) for i in range(n_tasks)]
job = Job()

for id in task_ids:
input_file = workspace_path.joinpath(
"job_{}".format(str(id)))

output_file = workspace_path.joinpath(
"job_{}_out".format(str(id)))

self.rust_worker.write_batch_input(
n_cores, n_points_per_task, export_grid, output_accumulator, str(workspace_path), id)

job.program(["bin/gammaloop_rust_cli", "batch", "--batch_input_file={}".format(str(input_file)),
"--name=massless_triangle", "--process_file=triangle", "--output_name={}".format(str(output_file))])

submitted = client.submit(job)
client.wait_for_jobs([submitted])

for id in task_ids:
self.rust_worker.process_batch_output(
str(workspace_path), id)

self.rust_worker.update_iter()
self.rust_worker.display_master_node_status()

shutil.rmtree(workspace_path)
1 change: 1 addition & 0 deletions python/gammaloop/misc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LOGGING_PREFIX_FORMAT = 'long' # options are: 'long', 'short', 'min' and 'none'
Loading

0 comments on commit c9aac0d

Please sign in to comment.