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

Add WaveForm and Enum dataypes #85

Open
evalott100 opened this issue Nov 20, 2024 · 3 comments · May be fixed by #102
Open

Add WaveForm and Enum dataypes #85

evalott100 opened this issue Nov 20, 2024 · 3 comments · May be fixed by #102
Assignees

Comments

@evalott100
Copy link
Contributor

WaveForm

Will be either a Sequence[T] where T is float, int, or str, or a numpy array with a dtype. This will not be an arg to the dataclass (not optional).

There will be a length on the datatype set to some sane default, since this is required by the EPICS and tango backends.

Enum

Will take a python enum.Enum type. When putting to the attribute you put the enum member not a string/int value itself. We will check on initialisation that all the values are either string or int.

We should keep allowed values for checking on Attribute.set, but I don't think that the current system of making and mbb record if it's a string with allowed values is as nice as having a dedicated Enum datatype that can be altered to whatever control system's enum definition.

Changes which will be required across datatypes.

DataType will now be given two additional attributes:

  • cast(T): For casting to a datatype which can be sent over the control system. It will also do some validation (i.e checking that an Int value doesn't exceed the maximum defined in the DataType).
WaveForm(Sequence[str]).cast(["a"]) == np.array(["a"], dtype="S40")
Enum(SomeEnum).cast(SomeEnum.member) -> "TheStringValueOfTheMember"
# Fails so that we don't have an internal value of the `Attribute` out of sync with the softioc.
Int(max=5).cast(6)
  • @property\intitial_value(): We can't rely on Attr._datatype.dtype() for an initial value anymore since the structured numpy array's has to be initialised with shape (length in our case) and dtype=. For enums this is true too. Therefore, we will use DataType.initial_value for the default initial value on attributes. This can be defaulted to self.dtype() in the Attribute base class.
@evalott100 evalott100 self-assigned this Nov 20, 2024
@GDYendell
Copy link
Contributor

GDYendell commented Nov 20, 2024

I think cast should be validate using the mechanism suggested here.

@GDYendell
Copy link
Contributor

We should keep allowed values for checking on Attribute.set

Can we just do self.dtype.validate(value) instead of keeping allowed_values on Attribute? Actually, I don't think it even validates against allowed_values currently.

@evalott100
Copy link
Contributor Author

evalott100 commented Nov 20, 2024

I think cast should be validate using the mechanism suggested here.

Okay, I'll move it to that PR.

Can we just do self.dtype.validate(value) instead of keeping allowed_values on Attribute? Actually, I don't think it even validates against allowed_values currently.

I'll make it so that an enum type which exceeds the epics limit for options comes out as a builder.string in the backend.

@evalott100 evalott100 linked a pull request Dec 13, 2024 that will close this issue
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 a pull request may close this issue.

2 participants