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

Follow RTD deprecation #563

Merged
merged 4 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion andes/variables/dae.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def set_t(self, t):
Helper function for setting time in-place.
"""

self.t.itemset(t)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function is meant to change self.t in place. The new implementation creates a new np.array for self.t. I can't recall other usages of self.t that assume a persistent memory. If that exists, the new implementation will fail: even though t is being updated here, the previous memory is being referred elsewhere.

Can you check: 1) if this function is called elsewhere? 2) any other implementation that changes t in place? I know numpy scalars are immutable; that's why itemset was used.

Copy link
Member Author

Choose a reason for hiding this comment

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

itemset is only used in the reset() method:

def reset(self):
"""
Reset array sizes to zero and clear all arrays.
"""
self.set_t(0.0)
self.m = 0
self.n = 0
self.o = 0
self.resize_arrays()
self.clear_ijv()
self.clear_ts()
def set_t(self, t):
"""
Helper function for setting time in-place.
"""
self.t.itemset(t)

I changed to in-place assignment, and the test shows below:

print(f"Memory address before: {ss.dae.t.ctypes.data}")
ss.dae.reset()
print(f"Memory address after: {ss.dae.t.ctypes.data}")

Memory address before: 4393601808
Memory address after: 4393601808

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks. Looks good! I didn't know triple dots do the trick!

Copy link
Member Author

Choose a reason for hiding this comment

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

I learnt this from GitHub Copilot just right now, a positive AGI datapoint!

self.t = np.array(t, dtype=float)

def get_size(self, name):
"""
Expand Down
5 changes: 5 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
import os
import andes
import shutil

Expand Down Expand Up @@ -131,6 +132,10 @@
"doc_path": "docs/source",
}

# Tell Jinja2 templates the build is running on Read the Docs
if os.environ.get("READTHEDOCS", "") == "True":
html_context["READTHEDOCS"] = True

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
Expand Down
2 changes: 2 additions & 0 deletions docs/source/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ v1.9 Notes

v1.9.3 (2024-04-XX)
-------------------
- In the `dae`` module, change `self.t.itemset` to array assignment to ensure compatibility with NumPy 2.0.
- Follow RTD's deprecation of Sphinx context injection at build time
- In symbolic processor, most variables are assumed to be real, except some
services that are specified as complex. This will allow generating simplified
expressions.
Expand Down
Loading