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

Implement open enumerations #56

Closed
lukaspie opened this issue Feb 18, 2025 · 5 comments · Fixed by #57
Closed

Implement open enumerations #56

lukaspie opened this issue Feb 18, 2025 · 5 comments · Fixed by #57
Assignees
Labels
enhancement New feature or request

Comments

@lukaspie
Copy link
Collaborator

lukaspie commented Feb 18, 2025

nexusformat/definitions#1521 introduced open enumerations, i.e., to allow values not explicitly given in the enumeration list. For this, a new attribute open was introduced for the enumerationTYPE, which defaults to "False". If open enumeration is used, this XML attribute should be "True".

In order to support this new feature, I suggest the following notation:

   <field name="mode">
   	<doc>source operating mode</doc>
   	<enumeration open="true">
   		<item value="Single Bunch"><doc>for storage rings</doc></item>
   		<item value="Multi Bunch"><doc>for storage rings</doc></item>
   	</enumeration>
   </field>

shall be expressed in nyaml as

  mode:
    doc: |
      source operating mode
    enumeration:
      \@open: True
      Single Bunch:
        doc: |
          for storage rings
      Multi Bunch:
        doc: |
          for storage rings

If \@open is not set, we default to <enumeration"> (i.e. open="False").

Using the \@ notation, we avoid situations where open is a valid enumeration value.

Opinions @sanbrock @mkuehbach @RubelMozumder ?

@lukaspie lukaspie added the enhancement New feature or request label Feb 18, 2025
@lukaspie lukaspie self-assigned this Feb 18, 2025
@lukaspie
Copy link
Collaborator Author

Our current notation like this

type:
    doc: |
      type of radiation source (pick one from the enumerated list and spell exactly)
    enumeration: [Spallation Neutron Source, Pulsed Reactor Neutron Source, Reactor Neutron Source, ...]

will likely not be able to handle this.

Another option we could go for is to add another special keyword, like

type:
    doc: |
      type of radiation source (pick one from the enumerated list and spell exactly)
    enumeration: [Spallation Neutron Source, Pulsed Reactor Neutron Source, Reactor Neutron Source, ...]
    open_enumeration: True

@mkuehbach
Copy link
Collaborator

mkuehbach commented Feb 18, 2025

enumeration:
  open: True

if combined with #52 will enable to process of an enumeration nest rigorously, i.e. convenience open: False the default

@lukaspie
Copy link
Collaborator Author

enumeration:
  open: True

if combined with #52 will enable to process of an enumeration nest rigorously, i.e. convenience open: False the default

This exactly won't work because currently we have enumeration: [Spallation Neutron Source, Pulsed Reactor Neutron Source, Reactor Neutron Source, ...], you cannot have an additional key in YAML there.

@mkuehbach
Copy link
Collaborator

enumeration: [enum values]  # if closed
enumeration:  # if open
  value: [enum values]
  open: boolean

Consistent with how it will be with dimensionsType

@lukaspie
Copy link
Collaborator Author

lukaspie commented Feb 19, 2025

enumeration: [enum values]  # if closed
enumeration:  # if open
  value: [enum values]
  open: boolean

Consistent with how it will be with dimensionsType

Hm, that makes the logic quite a bit more involved. How would that work for the first use case? Like so?

enumeration:
  open: True
  Single Bunch:
    doc: |
      for storage rings
  Multi Bunch:
    doc: |
      for storage rings

Then we need to distinguish enums

  • that are just a list
  • that are a dict with the open key and the value key (for this, we expect a list) (your case)
  • that are a dict with the value keyword and several other keys that are the actual enum items (my case in this comment)

Note that this means that neither open nor value can be used as enumeration items anymore. Maybe I would actually go for items instead of values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants