Skip to content

API: Add environment variable for behavior planned in a 2.0#23089

Merged
mattip merged 4 commits intonumpy:mainfrom
seberg:numpy2-flag
Feb 12, 2023
Merged

API: Add environment variable for behavior planned in a 2.0#23089
mattip merged 4 commits intonumpy:mainfrom
seberg:numpy2-flag

Conversation

@seberg
Copy link
Member

@seberg seberg commented Jan 25, 2023

The idea of the flag is not to allow to change it right now, since there may be some things where that is hard to do in general, and it doesn't seem relevant: nobody is supposed to use it besides for testing.


Maybe more for discussion, although I think it should be OK. My current thought is to have a single new process wide feature flag and not even bother with allowing to toggle it (at least for now).

I was planning to test run this with one of:

  • Disabling time promotions (there is an open PR)
  • Making string to bool conversions sane...

As well as enabling a single test-run. But both of those seemed to have trickier corner cases to deal with, so lets put this here to discuss.

It would be nice to do that test run including NPY_PROMOTION_STATE=weak, but that needs some fixes and some tests to be marked for skipping or adapted depending on the setting.

Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

This approach LGTM

@seberg
Copy link
Member Author

seberg commented Jan 26, 2023

One thing I may was planning on pushing later is the change that gradient returns tuples (which I think is so simple there is not much need for discussion). Just to have an example.

@seberg seberg force-pushed the numpy2-flag branch 2 times, most recently from cead66c to 512fe42 Compare January 26, 2023 12:13
@seberg
Copy link
Member Author

seberg commented Feb 9, 2023

Gentle ping on having an env variable as well (for behavior we would like to enable in NumPy 2)? Any thoughts on naming or the approach (or otherwise really?)

Copy link
Member

@mattip mattip left a comment

Choose a reason for hiding this comment

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

This seems staightforward enough. One small nit about having two instances that reflect this state. Should the documentation mention this will go away once we release numpy2?

npy_numpy2_behavior = PyObject_IsTrue(_is_numpy2);
Py_DECREF(_is_numpy2);
if (npy_numpy2_behavior < 0) {
return -1;
Copy link
Member

Choose a reason for hiding this comment

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

I think I would prefer there be one source of truth, and not have two global variables, one in C and one in Python

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I guess that would make this np._get_numpy2_behavior() would add a bit of call overhead, but that probably doesn't really matter. How does that sound?

Copy link
Member

Choose a reason for hiding this comment

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

great, thanks

Copy link
Member Author

Choose a reason for hiding this comment

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

Opted for np._using_numpy2_behavior(). Threading it out from C is a bit weird (going through numeric.py), but maybe it doesn't matter. I am now setting the variable directly in C.

The idea of the flag is not to allow to change it right now, since
there may be some things where that is hard to do in general, and
it doesn't seem relevant:  nobody is supposed to use it besides for
testing.
This change is staged for NumPy 2.0, I assume we could get away with
it otherwise, but it is a nice example and probably not pressing.
Copy link
Member

@mattip mattip left a comment

Choose a reason for hiding this comment

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

Thanks @seberg

if (env != NULL && strcmp(env, "0") != 0) {
npy_numpy2_behavior = NPY_TRUE;
}

Copy link
Member

Choose a reason for hiding this comment

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

It seems coverage is not gathering statistics from the appropriate CI run? That may be OK for now but will be problematic going forward

@mattip mattip merged commit 5c7fde6 into numpy:main Feb 12, 2023
@seberg seberg deleted the numpy2-flag branch February 12, 2023 07:16
@charris
Copy link
Member

charris commented May 25, 2023

@seberg What should we do with the contents of doc/release/numpy2_changes? Why is it separated?

@seberg
Copy link
Member Author

seberg commented May 25, 2023

I had a hope that we would add more :). Ignore it for now, I will copy it over into the normal release notes after branching.

@charris
Copy link
Member

charris commented May 25, 2023

We have branched, that is why I am asking, I'm working on the 1.25.0 release notes now.

@seberg
Copy link
Member Author

seberg commented May 25, 2023

Well, its irrelevant for the 1.25 notes I think. But after clearing out the current release notes, we can copy that one fragment over to the normal place and delete the folder.

@charris
Copy link
Member

charris commented May 25, 2023

That is for main, no? It is already cleared, I'll open a PR and move the note.

@seberg
Copy link
Member Author

seberg commented May 25, 2023

Yeah, but let me do it, I want to basically undo all of this PR (remove the var).

@charris
Copy link
Member

charris commented May 25, 2023

OK. It was #23811, I'll just redo that to remove the stray fragment that got merged to the root directory.

I'll just close it :)

seberg added a commit to seberg/numpy that referenced this pull request Jun 1, 2023
This effectively reverts most of numpygh-23089, the array function disabling
has been removed in the meantime, so the test is now not needed anymore
(the test set it to 0 before).

I am sad that there weren't actually any changes, but it doesn't really
matter.
seberg added a commit to seberg/numpy that referenced this pull request Jun 1, 2023
This effectively reverts most of numpygh-23089, the array function disabling
has been removed in the meantime, so the test is now not needed anymore
(the test set it to 0 before).

I am sad that there weren't actually any changes, but it doesn't really
matter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants