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

Weird missing numpy error on windows. #900

Open
iandobbie opened this issue Aug 20, 2024 · 8 comments
Open

Weird missing numpy error on windows. #900

iandobbie opened this issue Aug 20, 2024 · 8 comments

Comments

@iandobbie
Copy link
Collaborator

I have an error on cockpit startup but only on windows. Even with a "--no-config-file" flag the system produces the following error.

Traceback (most recent call last):
  File "C:\Users\idobbie1\src\cockpit\cockpit\__init__.py", line 163, in OnInit
    cockpit.util.userConfig.initialize(self.Config)
  File "C:\Users\idobbie1\src\cockpit\cockpit\util\userConfig.py", line 109, in initialize
    _config = _loadConfig(_config_path)
  File "C:\Users\idobbie1\src\cockpit\cockpit\util\userConfig.py", line 45, in _loadConfig
    config = eval(fh.read())
  File "<string>", line 407, in <module>
NameError: name 'np' is not defined

I don't understand what is trying to call np where it isn't defined.

This is with a fresh clone of upstream/master. The same code appears to be working fine on my mac, with no startup troubles.

@iandobbie
Copy link
Collaborator Author

Found the issue. It is in the user config which is of course system and user specific. The PC has...

'experimentAltitudes': [99.04205228121448,
                         99.04205228121448,
                         100.66569248254586,
                         100.66569248254586,
 .....
                         29.22552362396493,
                         np.float64(1250.0),
                         np.float64(1250.0),
                         np.float64(1250.0),
                         np.float64(1250.0)],

I was testing with numpy 2.0.0 just before I went away. I assume that the experiment altitudes need to be forced into a string before being saved in order to prevent this.

@iandobbie
Copy link
Collaborator Author

So removing the np.float lines prevents the error, so this is definitely the cause. My next question is why does --no-config-files still load the user config? Should we change the behaviour so it isn't loaded with this flag? I will work on a fix for the cause of the error.

@carandraug
Copy link
Collaborator

My next question is why does --no-config-files still load the user config? Should we change the behaviour so it isn't loaded with this flag?

See #577 . Yes, this is confusing but I'm not sure how to go about fixing this.

@iandobbie
Copy link
Collaborator Author

Ok, good point. As you say not sure what the best thing about loading the config.py is.

As to fixing the issue it doesn't seem to be trivial.

>>> import numpy as np
>>> np.__version__
'2.0.0'
>>> f=np.float64(15.34)
>>> f
np.float64(15.34)
>>> print(f)
15.34
>>> import pprint
>>> p=pprint.PrettyPrinter()
>>> p.pformat(f)
'np.float64(15.34)'

The config saving routine uses pprint.PrettyPrinter.pformat to format the output.

@iandobbie
Copy link
Collaborator Author

I guess we could cast the value to a python float when adding to the list which seems to be handled properly by the PrettyPrinter routines.

@carandraug
Copy link
Collaborator

Yes. From looking at it, I think something like this:

## Ensure that the value is a builtin float and not something else (see #900)       
self.experimentAltitudes.append(float(self.curStagePosition[2]))
cockpit.util.userConfig.setValue('experimentAltitudes', self.experimentAltitudes)

But did curStagePosition change type? Why is it a numpy float now?

@iandobbie
Copy link
Collaborator Author

Exactly my fix, just tested and it works.

It might have always been a numpy float but with numpy2 the prettyprint routines don't know how to print it.

@iandobbie
Copy link
Collaborator Author

In macroStageBase.py we have

        ## As above, but for the current position.
        self.curStagePosition = numpy.zeros(3)

So yes it always seemed to have been a numpy array.

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

No branches or pull requests

2 participants