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

fix closed CacheAdapter #847

Merged
merged 2 commits into from
Apr 26, 2024
Merged

fix closed CacheAdapter #847

merged 2 commits into from
Apr 26, 2024

Conversation

zilto
Copy link
Collaborator

@zilto zilto commented Apr 25, 2024

The CacheAdapter() would successfully run for the first execution, and fail on subsequent ones. This is because the cache was opened on __init__() (needs to read some attributes at instantiation) and closed "after graph execution".

Changes

cache is now opened and closed at __init__()
cache is opened "before graph execution" and closed "after graph execution" for satefy

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

@zilto zilto added the bug Something isn't working label Apr 25, 2024
Copy link
Collaborator

@elijahbenizzy elijahbenizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure this is the right solution...


def run_before_graph_execution(self, *, graph: HamiltonGraph, **kwargs):
"""Set `cache_vars` to all nodes if received None during `__init__`"""
self.cache = shelve.open(self.cache_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something feels wrong about this. Aren't we just opening it again? Feels like it should:

  1. Open during init
  2. Run during execution
  3. Close at the end

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, that was the previous behavior... I want to have .close() somewhere for safety, but putting it in run_after_graph_execution means you can only run it once

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't it just open again? Maybe:

  1. Open/close during __init__
  2. Open during run_before_graph_execution
  3. Run
  4. Close at run_after_graph_execution
    ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's what Thierry just did here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yes, my bad

Copy link
Collaborator

@elijahbenizzy elijahbenizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it! Sorry misunderstood a bit. This looks good.

@zilto zilto merged commit 5296232 into main Apr 26, 2024
23 checks passed
@zilto zilto deleted the fix/closed-cache branch April 26, 2024 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants