Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing minor issues on numcosmo command line tool #139

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions numcosmo_py/external/cosmosis.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import os
import math
from typing import List, Dict, Tuple, Optional, Iterator
from typing import List, Dict, Tuple, Optional
from pathlib import Path
from enum import Enum

Expand Down Expand Up @@ -62,7 +62,7 @@ class NonLinearMatterPowerSpectrum(str, Enum):
HALOFIT = "halofit"


def convert_parameter(p: Parameter, required_parameters: Iterator[str]) -> Ncm.SParam:
def convert_parameter(p: Parameter, required_parameters: List[str]) -> Ncm.SParam:
"""Converts a Cosmosis parameter to a NumCosmo parameter."""

matched_name = next(
Expand Down Expand Up @@ -109,7 +109,7 @@ def convert_parameter(p: Parameter, required_parameters: Iterator[str]) -> Ncm.S

def convert_single_model(
sampling_parameters_section: str,
required_parameters: Iterator[str],
required_parameters: List[str],
model_name: str,
parameters: List[Parameter],
) -> Tuple[Ncm.ModelBuilder, Ncm.Model]:
Expand Down Expand Up @@ -149,7 +149,7 @@ def convert_single_model(
def convert_models(
sampling_parameters_sections: List[str],
model_names_list: List[str],
required_parameters: Iterator[str],
required_parameters: List[str],
parameters: List[Parameter],
model_builders: Ncm.ObjDictStr,
mset: Ncm.MSet,
Expand Down Expand Up @@ -253,7 +253,9 @@ def convert_single_likelihood(
likelihood.peek_dataset().append_data(firecrown_data)

firecrown_likelihood = numcosmo_factory.get_firecrown_likelihood()
required_parameters = firecrown_likelihood.required_parameters().get_params_names()
required_parameters = list(
firecrown_likelihood.required_parameters().get_params_names()
)

# Converts the sampling parameters sections to NumCosmo models.
convert_models(
Expand Down
12 changes: 7 additions & 5 deletions tools/numcosmo
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,18 @@ class RunFit(RunCommonOptions):
" than the given tolerance (abstol, reltol)."
),
),
] = None
] = (None, None)

def __post_init__(self):
super().__post_init__()
self.fit.log_info()

if self.restart is None:
abstol, reltol = self.restart

if abstol is None or reltol is None:
self.fit.run(self.run_messages.genum)
else:
if self.restart[0] <= 0.0 and self.restart[1] <= 0.0:
if abstol <= 0.0 and reltol <= 0.0:
raise RuntimeError(f"Invalid tolerance for restart {self.restart}.")
output_filename = (
None
Expand All @@ -330,8 +332,8 @@ class RunFit(RunCommonOptions):
)
self.fit.run_restart(
self.run_messages.genum,
self.restart[0],
self.restart[1],
abstol,
reltol,
None,
output_filename,
)
Expand Down