Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

world.output_role.db = None leads to attribute error in DRL examples #512

Closed
AndreasEppler opened this issue Dec 9, 2024 · 16 comments · Fixed by #513
Closed

world.output_role.db = None leads to attribute error in DRL examples #512

AndreasEppler opened this issue Dec 9, 2024 · 16 comments · Fixed by #513
Assignees

Comments

@AndreasEppler
Copy link
Collaborator

Issue found by @mthede
When running 04_reinforcement_learning_algorithm_example.ipynb or 09_example_Sim_and_xRL.ipynb, the following issue emerges:
image
The issue occurs when calling world.output_role.delete_simular_runs() or world.output_role.get_sum_reward()
This appears to be due to a recent change in the WriteOutput class, where db is now initialized as None.
image
Adding the if-clause

if world.output_role.db is not None:
        world.output_role.delete_similar_runs()

to the run_learning function has been successfully found to be a quick fix for the issue that obviously does not address the problem at its root.

@maurerle
Copy link
Member

maurerle commented Dec 9, 2024

Hi, I doubt that this error comes from an uninitialized db_uri - if you do not provide a DB_URI, there should not be any output_role - not a has no attribute 'delete_similar_runs'.

Did you check if this occurs on main as well?
I have the feeling, that the two mentioned examples are not working that well.
I don't have any folder inputs/tutorial_09 locally for example..?

I fixed some issues for the output role in the attached PR though.

nick-harder pushed a commit that referenced this issue Dec 9, 2024
do not try to access self.db if we do not have a db_uri defined

closes #512
@AndreasEppler
Copy link
Collaborator Author

Hi, thanks for looking into it.
The inputs/tutorial_09 folder seems to be created and used in 10_DSU_and_flexibility.ipynb.
09_example_Sim_and_xRL.ipynb uses the inputs/tutorial_08 folder created by executing 08_market_zone_coupling.ipynb. The execution of notebook 08 is done at the beginning of notebook 09, however, the line was currently only executed in google colab. I'll fix this and create a PR.

@AndreasEppler AndreasEppler reopened this Dec 9, 2024
@maurerle
Copy link
Member

maurerle commented Dec 9, 2024

I think I understand now:

I renamed this function in d21a4e5

So one must use the matching assume version from main today.
Or use the new release which will be available soon.

@AndreasEppler
Copy link
Collaborator Author

AndreasEppler commented Dec 9, 2024

I don't think the renaming of the function is what is causing the issue, as I have today's main assume version. It seems to be due to self.db being initialized as None instead of db_engine. Does this make sense?

@maurerle
Copy link
Member

maurerle commented Dec 9, 2024

There is no way an object of type WriteOutput would not have the method delete_similar_runs with current main..

Maybe try to run python -m pip uninstall assume-framework and then run python -m pip install -e . or something? wrong env? wrong python interpreter running (which python or where python on windows)? different python interpreter when running python vs python3?

Does this happen in colab as well..?

@mthede
Copy link
Collaborator

mthede commented Dec 9, 2024

Initially, I found this issue when I was working with the Grafana training progress dashboard. When running the same example (small_learning_1) multiple times, the data from the last simulation is not deleted. With progressing episodes, it will only be overwritten.

I pulled your latest commits, looked into it again and it still doesn't succesfully delete the previous similar run.
In debug mode I saw that the self.db_uri is given, however self.db will be accessed and is `None'
grafik

@AndreasEppler
Copy link
Collaborator Author

AndreasEppler commented Dec 9, 2024

image
Yes, it's also happening in colab, reinstalling assume does not change anything aswell.

@maurerle
Copy link
Member

maurerle commented Dec 9, 2024

Sorry, I can't reproduce this. Maybe you can provide a minimal example for this?

I can only imagine that you are using an old release... try running:
!pip install https://github.com/assume-framework/assume/archive/refs/heads/main.zip or create a fresh env

But I don't think that this would block releasing the new software

@maurerle
Copy link
Member

maurerle commented Dec 10, 2024

Maybe you can check if you can still reproduce this, now that v0.5.0 is released

@mthede
Copy link
Collaborator

mthede commented Dec 10, 2024

The new version didn't change the behavior for me.

@mthede
Copy link
Collaborator

mthede commented Dec 10, 2024

In colab the AttributeError (screenshot from Andreas) is now resolved! We've just noticed that the progress bar is printed in a new line.
grafik

@mthede
Copy link
Collaborator

mthede commented Dec 10, 2024

[Edit: Ok, wait, I'll need to check again]

@mthede
Copy link
Collaborator

mthede commented Dec 10, 2024

The behavior seems to be the same with the new release. I restarted docker (had to change the path for volumes again from ./assume-db:/home/postgres/pgdata to ./assume-db:/home/postgres/data for the timescaledev image) and checked that I'm working with the latest release.

I'm not sure if a minimal example helps if it's caused by some version/environment error... but I'll try to explain/how it by going through the code.

Try examples.py with small_learning_1 and add episode=0 in load_scenario_folder():
grafik

[BTW: the default for episode/eval_episode is set to 1 in load_scenario_folder() , although docs say "Defaults to 0."]

The output role will then initialize self.db = None in line 83 and in line 98 call delete_similar_runs().
grafik

Now, an Exception is caught because self.db is still None and self.db.begin() is not possible.
grafik

Does that help?

@maurerle
Copy link
Member

@mthede
I still can't reproduce this issue.
Are you sure the error message did not change since the release?

Maybe someone else can try to reproduce and fix this.

@mthede
Copy link
Collaborator

mthede commented Dec 10, 2024

With the described example above, I don't get an error message either. I just noticed the unexpected behavior that similar runs were not deleted in the database. But that was fixed with your most recent PR, I've already tried it.

The errors described by Andreas from the notebooks seem to be resolved with the new release. (Maybe @AndreasEppler can confirm this again, but he told me that example 9 fully ran without any problems.)

So most likely we were talking about two different issues? Both seem to be fixed :) thanks!

@nick-harder
Copy link
Member

fixed in #519

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants