Skip to content

Commit

Permalink
Merge pull request sxs-collaboration#6112 from knelli2/default_horizo…
Browse files Browse the repository at this point in the history
…ns_h5

Optionally specify path to Horizons.h5 in Inspiral CLI
  • Loading branch information
nilsvu authored Jun 25, 2024
2 parents 31e9e91 + ea59c1a commit f440a83
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
38 changes: 37 additions & 1 deletion support/Pipelines/Bbh/Inspiral.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def _constraint_damping_params(
def inspiral_parameters(
id_input_file: dict,
id_run_dir: Union[str, Path],
id_horizons_path: Optional[Union[str, Path]],
refinement_level: int,
polynomial_order: int,
) -> dict:
Expand All @@ -89,14 +90,29 @@ def inspiral_parameters(
id_input_file: Initial data input file as a dictionary.
id_run_dir: Directory of the initial data run. Paths in the input file
are relative to this directory.
id_horizons_path: Path to H5 file containing information about the
horizons in the ID (e.g. mass, spin, spherical harmonic coefficients).
If this is 'None', the default is the 'Horizons.h5' file inside
'id_run_dir'.
refinement_level: h-refinement level.
polynomial_order: p-refinement level.
"""
id_domain_creator = id_input_file["DomainCreator"]["BinaryCompactObject"]
id_binary = id_input_file["Background"]["Binary"]

# ID parameters
horizons_filename = Path(id_run_dir) / "Horizons.h5"
horizons_filename = (
Path(id_horizons_path)
if id_horizons_path is not None
else Path(id_run_dir) / "Horizons.h5"
)
if not horizons_filename.is_file():
raise ValueError(
f"The ID horizons path ({str(horizons_filename.resolve())}) does"
" not exist. If there is no 'Horizons.h5' file in your ID"
" directory, run 'spectre bbh postprocess-id' on the ID to"
" generate it."
)
initial_separation = (
id_domain_creator["ObjectA"]["XCoord"]
- id_domain_creator["ObjectB"]["XCoord"]
Expand Down Expand Up @@ -272,6 +288,7 @@ def start_inspiral(
inspiral_input_file_template: Union[
str, Path
] = INSPIRAL_INPUT_FILE_TEMPLATE,
id_horizons_path: Optional[Union[str, Path]] = None,
continue_with_ringdown: bool = False,
pipeline_dir: Optional[Union[str, Path]] = None,
run_dir: Optional[Union[str, Path]] = None,
Expand Down Expand Up @@ -316,6 +333,7 @@ def start_inspiral(
inspiral_params = inspiral_parameters(
id_input_file,
id_run_dir,
id_horizons_path=id_horizons_path,
refinement_level=refinement_level,
polynomial_order=polynomial_order,
)
Expand Down Expand Up @@ -402,6 +420,24 @@ def start_inspiral(
help="Input file template for the inspiral.",
show_default=True,
)
@click.option(
"--id-horizons-path",
type=click.Path(
exists=True,
file_okay=True,
dir_okay=False,
readable=True,
path_type=Path,
),
default=None,
show_default="Horizons.h5 inside 'id-run-dir'",
help=(
"H5 file that holds information of the horizons of the ID solve. If"
" this file does not exist in your ID directory, run 'spectre bbh"
" postprocess-id' in the ID directory to generate it. Note that this is"
" not needed if you are starting from a SpEC ID_Params.perl file."
),
)
@click.option(
"--refinement-level",
"-L",
Expand Down
6 changes: 5 additions & 1 deletion tests/support/Pipelines/Bbh/Test_Inspiral.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def setUp(self):
executable=str(self.bin_dir / "SolveXcts"),
)
self.id_dir = self.test_dir / "ID"
self.horizons_filename = self.id_dir / "Horizons.h5"
# Purposefully not in the ID directory
self.horizons_filename = self.test_dir / "Horizons.h5"
with spectre_h5.H5File(
str(self.horizons_filename.resolve()), "a"
) as horizons_file:
Expand All @@ -60,6 +61,7 @@ def test_inspiral_parameters(self):
params = inspiral_parameters(
id_input_file=id_input_file,
id_run_dir=self.id_dir,
id_horizons_path=self.horizons_filename,
refinement_level=1,
polynomial_order=5,
)
Expand Down Expand Up @@ -109,6 +111,8 @@ def test_cli(self):
"1",
"--polynomial-order",
"5",
"--id-horizons-path",
str(self.horizons_filename),
"-E",
str(self.bin_dir / "EvolveGhBinaryBlackHole"),
]
Expand Down

0 comments on commit f440a83

Please sign in to comment.