Code Monkey home page Code Monkey logo

Comments (9)

tillkolster avatar tillkolster commented on May 24, 2024

Things that are not saved properly are:
location of cell, cell of individual and so on, so attributes that are not part of a process yet. Maybe this is solving itself if they become part of processes!

from pycopancore.

tillkolster avatar tillkolster commented on May 24, 2024

the question is now more: is this a bug? Do we need iterating through all variables? If they don't change, do we need their information? Or is it enough to get the information once, not every time a discontinuity is called?

from pycopancore.

tillkolster avatar tillkolster commented on May 24, 2024

Code proposal:

for (v, oc) in  self.ODE_variables,  self.explicit_variables,  self.step_variables,  self.event_variables:
        entities = oc.entities
        values = v.get_value_list(entities)
        for i in range(len(entities)):
            entity = entities[i]
            value = np.array([values[i]])
            try:
                trajectory_dict[v][entity] = np.concatenate((
                    trajectory_dict[v][entity], value))
            except KeyError:
                trajectory_dict[v][entity] = value
    t_np = np.array([t])
    trajectory_dict['t'] = np.concatenate((trajectory_dict['t'], t_np))

So the first line has changed from self.model.variables to the variables that change. Now, after finishing the while loop, do following:

for (v,oc) in self.model.variables and not in self.ODE_variables, self.explicit_variables, self.step_variables, self.event_variables:
    entities = oc.entities
                values = v.get_value_list(entities)
                for i in range(len(entities)):
                    entity = entities[i]
                    value = np.array([values[i]])
                    try:
                        trajectory_dict[v][entity] = np.concatenate((
                            trajectory_dict[v][entity], value))
                    except KeyError:
                        trajectory_dict[v][entity] = value
return trajectory_dict

Maybe there are some errors, but this is the idea

from pycopancore.

KilianZimmerer avatar KilianZimmerer commented on May 24, 2024

I agree with you.The code proposal also make sense since the performance will be better.

from pycopancore.

KilianZimmerer avatar KilianZimmerer commented on May 24, 2024

To make it easier to implement further processes in a later stage it might does make sense to reintroduce the process_variables in model.py.

from pycopancore.

jakobkolb avatar jakobkolb commented on May 24, 2024

Just a small proposal:
Instead of

for i in range(len(things)):
    thing = things[i]
    ...

you could use

for i, thing in enumerate(things):
    ...

from pycopancore.

KilianZimmerer avatar KilianZimmerer commented on May 24, 2024

Thank you! Just changed it.

from pycopancore.

timkittel avatar timkittel commented on May 24, 2024

While we are at that, two more comments (:
(1) maybe simply use zip
(2) Usually it's good to avoid try except staements in Python, following the Zen of Python's (PEP20) "Explicit is better than implicit."

maybe simple use:

        for entity, value in zip(entities, values):
            if entity in trajectory[v]:
                trajectory_dict[v][entity] = np.concatenate((
                    trajectory_dict[v][entity], value))
            else:
                trajectory_dict[v][entity] = np.array([value])

It shortens the whole thing and makes it directly readable.

from pycopancore.

KilianZimmerer avatar KilianZimmerer commented on May 24, 2024

Yes, I think it makes sense to change this, I put that suggestions into a separate issue #52 that only concerns code enhancement/improvement .
Since the main problem of this issue is already solved I closed it.

from pycopancore.

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.