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

P11 develop #800

Closed
wants to merge 159 commits into from
Closed

P11 develop #800

wants to merge 159 commits into from

Conversation

agruzinov
Copy link
Contributor

Here is another round of debug after upgrading to the latest code (mostly in DESY HO).

Andrey Gruzinov added 23 commits September 18, 2023 12:11
…y for shutter-like objects inside P11 HO (Bixente)
…y for shutter-like objects inside P11 HO (Bixente)
@@ -121,7 +121,7 @@ def load_positions(self):
def get_position_list(self):
return list(self._positions.keys())

def get_properties_(self, position_index, property_name):
def get_properties(self, position_index, property_name):
Copy link
Contributor

Choose a reason for hiding this comment

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

If I am not mistaken, there is already a get_properties in one of the parent classes. Namely in HardwareObjectNode, via HardwareObject and AbstractActuator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comment. Changed.

Comment on lines 45 to 54
@unique
class BaseValueEnum(Enum):
"""Defines only the compulsory values."""
OPEN = "OPEN"
CLOSED = "CLOSED"
MOVING = "MOVING"
UNKNOWN = "UNKNOWN"

VALUES=BaseValueEnum
"""Defines only the compulsory values."""

OPEN = "OPEN"
CLOSED = "CLOSED"
MOVING = "MOVING"
UNKNOWN = "UNKNOWN"

VALUES = BaseValueEnum
Copy link
Member

@beteva beteva Oct 7, 2023

Choose a reason for hiding this comment

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

As it inherits from AbstractShutter, no need to do this. Please see my comment comment below

Comment on lines 67 to 77
def get_value(self):
return self.update_fast_shutter()

@property
def is_open(self):
return self.get_value() == self.VALUES.OPEN

@property
def is_closed(self):
return self.get_value() == self.VALUES.CLOSED

Copy link
Member

Choose a reason for hiding this comment

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

No need to define FastShutterVakue enum. As it inherits from AbstractNState, uou can simply do it in your xml file, like this:
<values>{"OPEN": "Open", "CLOSED": "Closed"}</values>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comment. What is best way to adress it from the code?

Copy link
Member

Choose a reason for hiding this comment

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

Can you, please, be more explicit. The above comment means, that your self.VALUES.OPEN.value is "Open", as you probably need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is my xml:

FastShutter
<tangoname>p11/shutter/fs</tangoname>

<channel type="tango" name="value" polling="500">value</channel>

<values>{"OPEN": "Open", "CLOSED": "Closed"}</values>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And mxcube is not happy:

File "/mxcubecore/mxcubecore/HardwareRepository.py", line 545, in parse_xml
hardware_obj = HardwareObjectFileParser.parse_string(xml_string, ho_name)
File "/mxcubecore/HardwareObjectFileParser.py", line 78, in parse_string
xml.sax.parseString(str.encode(xml_hardware_object), cur_handler)
File "/usr/lib/python3.7/xml/sax/init.py", line 48, in parseString
parser.parse(inpsrc)
File "/usr/lib/python3.7/xml/sax/expatreader.py", line 111, in parse
xmlreader.IncrementalParser.parse(self, source)
File "/usr/lib/python3.7/xml/sax/xmlreader.py", line 125, in parse
self.feed(buffer)
File "/usr/lib/python3.7/xml/sax/expatreader.py", line 217, in feed
self._parser.Parse(data, isFinal)
File "../Modules/pyexpat.c", line 417, in StartElement
File "/usr/lib/python3.7/xml/sax/expatreader.py", line 333, in start_element
self._cont_handler.startElement(name, AttributesImpl(attrs))
File "HardwareObjectFileParser.py", line 276, in startElement
new_object = instanciate_class(module_name, class_name, object_name)
HardwareObjectFileParser.py", line 105, in instanciate_class
module = load_module(module_name)
File "/gpfs/local/shared/MXCuBE/mxcubecore/mxcubecore/HardwareObjectFileParser.py", line 91, in load_module
return import(hardware_object_name, globals(), locals(), [""])
File "mxcubecore/HardwareObjects/DESY/P11FastShutter.py", line 41, in
class P11FastShutter(AbstractNState):
File "/usr/lib/python3.7/enum.py", line 862, in unique
for name, member in enumeration.members.items():
AttributeError: type object 'P11FastShutter' has no attribute 'members'
2023-11-08 18:23:30,869 |HWR |ERROR | Failed to load Hardware object /fast-shutter

Comment on lines 42 to +51
@unique
class BaseValueEnum(Enum):
"""Defines only the compulsory values."""
OPEN = "OPEN"
CLOSED = "CLOSED"
MOVING = "MOVING"
UNKNOWN = "UNKNOWN"

VALUES=BaseValueEnum
"""Defines only the compulsory values."""

OPEN = "OPEN"
CLOSED = "CLOSED"
MOVING = "MOVING"
UNKNOWN = "UNKNOWN"

VALUES = BaseValueEnum
Copy link
Member

@beteva beteva Oct 7, 2023

Choose a reason for hiding this comment

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

As you inherit from AbstractShutter, no need to do this. Please see my comment below.

@beteva
Copy link
Member

beteva commented Oct 7, 2023

Dear @agruzinov,
there is a way to add extra values, without redefining the BaseValueEnum. The values are always accessible via self.VALUES, as you can find it attributed in this case in AbstractShutter. If you want to add extra values to this enum, you can add it like this:

def _initialise_values(self):
        """Add additional, known in advance states to VALUES"""
        values_dict = {item.name: item.value for item in self.VALUES}
        values_dict.update(
            {
                "MOVING": "In Motion",
                "UNUSABLE": "Temporarily not controlled",
            }
        )
        self.VALUES = Enum("ValueEnum", values_dict)

And in the init, you simply add:
self._initialise_values()
Thus you simply add whatever you need. Please have a look in the ShutterMockup

Copy link
Contributor

@fabcor-maxiv fabcor-maxiv left a comment

Choose a reason for hiding this comment

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

_get_property vs. get_property, see earlier inline comment

@agruzinov agruzinov marked this pull request as ready for review December 2, 2023 19:29
Copy link
Contributor

@fabcor-maxiv fabcor-maxiv left a comment

Choose a reason for hiding this comment

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

This still seems to include changes (whole commits?) that have already been merged. The pull request contains 159 commits! To me this is usually a hint that some git operations (rebase maybe?) did not go well. I recommend to take some time to investigate and fix this. Maybe make sure to extract your actual changes from the ones that are merged upstream, then squash some commits to get the number down from 159.

Now for review itself I will only look at what is outside of the DESY directory.

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to contain only cosmetic changes. Do we want such changes in a pull request for a file that is otherwise untouched? What is the policy? @marcus-oscarsson

Copy link
Contributor

Choose a reason for hiding this comment

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

This change was already merged in be49e6d

Comment on lines +809 to +810
self.log.debug(f" Found sample {smp} is loaded")
self.log.debug(f" getting loaded {self.get_loaded_sample()}")
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I know, the recommendation for logging in Python is to always use the "printf style formatting" (with % interpolation): https://docs.python.org/3/library/stdtypes.html#old-string-formatting

Copy link
Member

Choose a reason for hiding this comment

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

This is true. The best to satisfy both python recommendations and pylint would be to change to:

msg = f" Found sample {smp} is loaded\n   getting loaded {self.get_loaded_sample()}"
self.log.debug(msg)

Copy link
Contributor

Choose a reason for hiding this comment

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

Does pylint complain about printf style formatting for logging? It shouldn't, should it?

Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately it does both - complains about not using f-string (which is in the log) and complains when using f-string in log. A bit of a mess, really.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Using pylint 2.15.4

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this okay?

self.log.debug("Found sample %s is loaded", smp)
self.log.debug("   getting loaded %s", self.get_loaded_sample())

Seems fine for me with the same Pylint version 2.15.4 and the same .pylintrc configuration file.

@marcus-oscarsson
Copy link
Member

Iam sorry @agruzinov I lost track of things, is this PR still active ?

@agruzinov
Copy link
Contributor Author

In principle yes. I guess the main issue for now is the some problems with rebase. Maybe it is better to close it for now and open a new PR then??

@agruzinov
Copy link
Contributor Author

PR needs to be resubmitted. Closing.

@agruzinov agruzinov closed this Feb 20, 2024
Comment on lines +106 to +110
if self._updating_value:
return # Already updating, avoid recursion

self._updating_value = True

Copy link
Member

@beteva beteva Feb 20, 2024

Choose a reason for hiding this comment

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

@agruzinov, could you tell us, please, where in the sample changer you get recursion ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@beteva It looks like you are reviewing a closed pull request. If I understood correctly a new pull request has been created for the same change(s): #854

Comment on lines +42 to +49
self.focus_sizes = {
-1: {"label": "unknown", "size": (0.2, 0.2)},
0: {"label": "flat", "size": (0.2, 0.2)},
1: {"label": "200x200", "size": (0.2, 0.2)},
2: {"label": "100x100", "size": (0.1, 0.1)},
3: {"label": "50x50", "size": (0.05, 0.05)},
4: {"label": "20x20", "size": (0.02, 0.02)},
5: {"label": "4x9", "size": (0.009, 0.004)},
Copy link
Member

Choose a reason for hiding this comment

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

You have this both in DigitalZoomMotor and here. I am afraid this is prone to errors. Is it not possible to have it only in one place and get it in the other Hardware object

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 this pull request may close these issues.

6 participants