Skip to content

Conversation

@SBouchard01
Copy link
Collaborator

@SBouchard01 SBouchard01 commented Jan 21, 2026

I split the Observable.__init__ method in several functions, which now allow to either load the datasets and models trough the paths dict, or trough the dataset & model arguments.

I removed the checkpoint_fn attribute, which now has been passed as a legacy argument to __init__

Note

I still need to propagate this change to the EMC classes, which all have their checkpoint hardcoded (this should be changed along with the file structure for the next pipeline runs)

I added load() and save() methods to allow loading and saving for file, but those are not implemented yet (Redundant with compressed files & model checkpoint, I'm giving up on this idea)

@SBouchard01 SBouchard01 self-assigned this Jan 21, 2026
@SBouchard01 SBouchard01 added enhancement New feature or request Observables Related to acm.observables labels Jan 21, 2026
@SBouchard01
Copy link
Collaborator Author

Also, this might have conflicts with #133

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Observable class initialization to provide more flexibility in loading datasets and models. The refactoring splits the monolithic __init__ method into separate concerns and allows users to either provide pre-loaded data/models or load them from file paths.

Changes:

  • Refactored Observable.__init__ to accept dataset and model as optional direct parameters, with paths as a fallback for loading from files
  • Extracted dataset and model loading logic into separate class methods (load_dataset_from_files and load_model)
  • Added placeholder load() and save() methods for future implementation
  • Updated __repr__ to provide detailed object inspection

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 11 comments.

File Description
acm/observables/base.py Refactored Observable class to support both direct parameter passing and file-based loading, extracted loading logic into separate class methods, and improved object representation
.gitignore Added .vscode/ directory to ignored files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 107 to 118
if model is None:
try:
if checkpoint_fn is not None:
self.logger.warning("The 'checkpoint_fn' parameter is deprecated. Please use 'paths['model_dir']/stat_name.ckpt' instead.")
checkpoint_fn = Path(checkpoint_fn)
else:
checkpoint_fn = Path(paths['model_dir']) / f'{stat_name}.ckpt'
model = self.load_model(checkpoint_fn)
except Exception as e:
self.logger.warning(f"Could not load model from checkpoint: {e}")

self.model = model
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When model loading fails, model remains None and is assigned to self.model. While this may be intentional (as indicated by the warning message), this creates an inconsistent state where self.model exists but is None. This could lead to AttributeErrors in code that expects self.model to be defined when it exists. Consider either not setting self.model at all when loading fails, or documenting this behavior more clearly in the class docstring.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@epaillas what do you think would be the best approach here? In both case it will crash, but not defining the model seems more rigorous in term of error handling...

@SBouchard01 SBouchard01 marked this pull request as ready for review January 21, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Observables Related to acm.observables

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow observables to load with a dataset

2 participants