Giter Club home page Giter Club logo

Comments (4)

uinone avatar uinone commented on June 26, 2024 2

Thanks for the explanation! I'll try my best.

from brim.

uinone avatar uinone commented on June 26, 2024

Hello, I am a student trying to contribute for the first time. I'm asking a question because I don't quite understand the issue. Looking at the issue content, it looks like I need to simply create a static method that returns self.symbol. Is my understanding correct?

from brim.

tjstienstra avatar tjstienstra commented on June 26, 2024

Each component in BRiM has an attribute symbols, which is a dictionary mapping descriptive names to the symbol objects, e.g. {"radius": self.Symbol(f"{self.name}_radius")}. This new method should gather all the defined symbols in a model and return it as a set. The bigger picture is that a user can quickly check if (s)he forgot to define any symbols. I would expect the function to have the following format, but if you have better ideas feel free to make suggestions:

from sympy import Basic
from sympy.physics.mechanics import find_dynamicsymbols, dynamicsymbols

def get_all_symbols(self) -> set[Basic]:
    """Get all declared symbols of a model."""
    syms = set()
    # Get local symbols.
    for sym in model.symbols.values():
        # Extract symbols if an expression is set as symbol.
        if isinstance(sym, Basic):
            syms.update(sym.free_symbols)
            syms.update(find_dynamicsymbols(sym))
    if dynamicsymbols._t in syms:  # Remove t.
        syms.remove(dynamicsymbols._t)
    # Traverse children.
    if hasattr(self, "submodels"):
        for submodel in self.submodels:
            syms.update(get_all_symbols(submodel))
    if hasattr(self, "connections"):
        for conn in self.connections:
            syms.update(get_all_symbols(conn))
    if hasattr(self, "load_groups"):
        for load_group in self.load_groups:
            syms.update(get_all_symbols(load_group))
    return syms

P.S. I just required this function, so I wrote up a quick implementation. For testing, I would advise a few tests. One to check the traversal in general. And one using pytest.mark.parametrize to check the different overrides of symbols, e.g. wheel.symbols["r"] = expr, where expr can be Symbol("r"), 0, 1, dynamicsymbols("r"), Symbol("r_def") - dynamicsymbols("r_var").

from brim.

tjstienstra avatar tjstienstra commented on June 26, 2024

Due to inactivity, this issue will be solved in #111

from brim.

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.