GSoC Week 3 & 4: Refactoring build_posterior and Improving Design


GSOC
gsoc python open-source sbi refactoring api-design

Hi everyone! I’m back with another update on my GSoC 2025 journey with the sbi project. Weeks 3 and 4 were focused on improving the architectural design of the build_posterior API and pushing forward the refactor work. Here’s a breakdown of my progress:

What I Worked On:

  • Finalized and pushed the implementation for the build_posterior method refactor PR.
  • Reviewed and addressed feedback on an open PR that introduced Protocols to the codebase.
  • Had a valuable discussion with my mentor about possibly splitting the build_posterior refactor into smaller, more focused PRs. Based on that, I updated the current PR to include only the annotation-related updates for clarity and maintainability.
  • Continued refining my understanding of design principles by reviewing the Head First Design Patterns book.
  • Restructured the build_posterior API to reduce code duplication across 5 trainer classes, better enforcing the DRY principle.
  • Raised a PR that adds a build_posterior method in the NeuralInference base class for handling posterior creation. With the updated implementation trainers inheriting from the NeuralInference base class now call the parent method to create a posterior, thus centralizing the posterior creation logic to a single place and removing duplicated conditional posterior creation logic previously found in each sub-class.
  • Implemented a PosteriorFactory class to standardize the creation of Posterior instances, making the API more extensible and easier to maintain.
  • Renamed the VectorFieldInference class to VectorFieldTrainer to align with naming conventions.

These two weeks brought a lot of progress in strengthening the foundation of the build_posterior functionality. I’m looking forward to tackling the next phase of this refactor and collaborating more with the team!