Git Product home page Git Product logo

Comments (4)

kmantel avatar kmantel commented on July 17, 2024

In this case, the problem isn't that the Distance instance is used as a class default for termination_measure, it's that there is an instance created as the default argument to termination_measure in __init__:

termination_measure=Distance(metric=MAX_ABS_DIFF),

This is created once on import, and then used for every TransferMechanism without that argument specified. In general, the exact object passed in to a constructor will be used as the parameter value. The exception is for the function parameter, which would make a copy of the object if it was already used by another Mechanism (the function's owner is not None).

A quick fix would be to just set the default argument value in TransferMechanism.__init__ above to None. This would have the default set properly for termination_measure, (And in general, they should be None, so the _user_specified Parameter flag is set correctly, so this would be a good change regardless) but it would still leave this example with the current behavior:

>>> dist = pnl.Distance()
>>> a = pnl.TransferMechanism(termination_measure=dist)
>>> b = pnl.TransferMechanism(termination_measure=dist)
>>> a.defaults.termination_measure is b.defaults.termination_measure
True

I think in general though, the function behavior should be expanded to other "subfunction" parameters

from psyneulink.

jvesely avatar jvesely commented on July 17, 2024

is the change in init a one-liner that should work, or does it trigger changes elsewhere? Do you have plans to work on it?
The example is OK. It probably won't work with compilation, but the sharing is clearly intended.

from psyneulink.

kmantel avatar kmantel commented on July 17, 2024

The change should work, because the Parameter default will be used when the argument to init is None. Using None should be the correct pattern in general because it will let us know if the user passed in an argument or not. It's been a low priority task to go through and change all those, but it can be bumped up as necessary. I have a commit that will make the change in this case, but it looks like I haven't pushed it yet.

I guess I'm not sure what's the best thing to do with the example. For function we definitely wanted protection from instances being shared; I'm not sure if the same pattern should hold for other parameters that happen to take functions.

from psyneulink.

jvesely avatar jvesely commented on July 17, 2024

Fixed in ded82bf

from psyneulink.

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.