Skip to content

Commit

Permalink
fixes logging (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
bananenpampe authored Jul 26, 2024
1 parent aa6dc91 commit 5e6bbaf
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/shiftml/ase/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, model_version, force_download=False):
# it is required for the scripted model
import rascaline.torch

logging.info(rascaline.torch.__version__)
logging.info("rascaline version: {}".format(rascaline.torch.__version__))
logging.info("rascaline-torch is installed, importing rascaline-torch")

assert (
Expand All @@ -73,7 +73,9 @@ def __init__(self, model_version, force_download=False):
self.outputs = resolve_outputs[model_version]
self.fitted_species = resolve_fitted_species[model_version]
logging.info("Found model version in url_resolve")
logging.info("Resolving model version to model files at url: ", url)
logging.info(
"Resolving model version to model files at url: {}".format(url)
)
except KeyError:
raise ValueError(
f"Model version {model_version} is not supported.\
Expand All @@ -92,19 +94,25 @@ def __init__(self, model_version, force_download=False):

if os.path.exists(model_file) and force_download:
logging.info(
f"Found {model_version} in cache, but force_download is set to True"
"Found {} in cache, but force_download is set to True".format(
model_version
)
)
logging.info(
f"Removing {model_version} from cache and downloading it again"
"Removing {} from cache and downloading it again".format(
model_version
)
)
os.remove(model_file)
download = True

else:
if os.path.exists(model_file):
logging.info(
f"Found {model_version} in cache,\
and importing it from here: {cachedir}"
"Found {} in cache,\
and importing it from here: {}".format(
model_version, cachedir
)
)
download = False
else:
Expand All @@ -113,23 +121,31 @@ def __init__(self, model_version, force_download=False):

if download:
urllib.request.urlretrieve(url, model_file)
logging.info(f"Downloaded {model_version} and saved to {cachedir}")
logging.info(
"Downloaded {} and saved to {}".format(model_version, cachedir)
)

except urllib.error.URLError as e:
logging.error(
f"Failed to download {model_version} from {url}. URL Error: {e.reason}"
"Failed to download {} from {}. URL Error: {}".format(
model_version, url, e.reason
)
)
raise e
except urllib.error.HTTPError as e:
logging.error(
f"Failed to download {model_version} from {url}.\
HTTP Error: {e.code} - {e.reason}"
"Failed to download {} from {}.\
HTTP Error: {} - {}".format(
model_version, url, e.code, e.reason
)
)
raise e
except Exception as e:
logging.error(
f"An unexpected error occurred while downloading\
{model_version} from {url}: {e}"
"An unexpected error occurred while downloading\
{} from {}: {}".format(
model_version, url, e
)
)
raise e

Expand Down

0 comments on commit 5e6bbaf

Please sign in to comment.