Code Monkey home page Code Monkey logo

Comments (3)

AdrienCorenflos avatar AdrienCorenflos commented on May 29, 2024

Hi!
First of all, nice work on thw waste free SMC @hai-dang-dau !
On this, testing for behaviour based on the presence or absence of an attribute is an antipattern an can lead to issues as you highlighted. This should be handled by the inheritance contract, so the real thing to check is if self is an instance of APFMixin (or AuxiliaryPF, depending on logic). The way I would go around it is to delete the isAPF altogether and then replace its use by a direct isinstance check. For instance this

if self.fk.isAPF:

would be replaced more cleanly by

if isinstance(self.fk, AuxiliaryPF):

if you are worried about circular imports, you can also use local imports of AuxiliaryPF

from particles.

hai-dang-dau avatar hai-dang-dau commented on May 29, 2024

@AdrienCorenflos Thanks for your feedback. I do not entirely agree with the type checking solution because that seems to go against Python's "duck typing" philosophy (i.e. any object with the logeta method should work with the implementation, regardless of its type).

My proposition would be to add a boolean-valued useAPF keyword argument in the SMC class. My arguments are:

(1) Even if a FeynmanKac object does include the logeta method, the user may, out of curiosity, prefers running the standard filter instead and sets useAPF=False.

(2) If useAPF is set to True, the implementation shall call fk.logeta without checking. So if the user passes in a FeynmanKac object without logeta method and sets useAPF=True, an AttributeError is therefore automatically raised (which is what we want anyway).

from particles.

nchopin avatar nchopin commented on May 29, 2024

I applied the quick fix recommended by Dang. Now things should work as expected.
But it's true that the current design is a bit dodgy, as proved by this "silent bug". I'll think about it.

from particles.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.