Skip to content

Conversation

@dee-mew
Copy link
Collaborator

@dee-mew dee-mew commented Oct 7, 2025

Updates in imas source and test files for handling alias information for identifiers as per issue #71.

Copy link
Collaborator

@maarten-ic maarten-ic left a comment

Choose a reason for hiding this comment

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

Hi @dee-mew, @olivhoenen,

A little more comments than I'd have liked, sorry 😅 Let me know if anything's unclear, feel free to send me a message on Slack and/or set up a short call to discuss 🙂

@olivhoenen olivhoenen linked an issue Oct 8, 2025 that may be closed by this pull request
@olivhoenen olivhoenen added this to the 2.0.2 milestone Oct 11, 2025
@maarten-ic
Copy link
Collaborator

Hi @dee-mew,

Sorry for taking over this PR and pushing to your branch :)

Couple of comments why I changed things:

  1. You can make it a lot easier for yourself by restricting the aliases argument (in IDSIdentifier.__init__) to a list. This removes quite a bit of parsing code (you're already parsing strings in _from_xml! 🙂)
  2. IDSIdentifier.alias didn't exist before this PR, no need to keep it for backwards compatibility
  3. Aliases / names are guaranteed to be unique -- this is checked in the Data Dictionary CI pipeline, so we don't need to check that when constructing the identifier
  4. I've added a test with custom identifier XML to test that multiple aliases works correctly

@dee-mew
Copy link
Collaborator Author

dee-mew commented Oct 14, 2025

Hi @dee-mew,

Sorry for taking over this PR and pushing to your branch :)

Couple of comments why I changed things:

  1. You can make it a lot easier for yourself by restricting the aliases argument (in IDSIdentifier.__init__) to a list. This removes quite a bit of parsing code (you're already parsing strings in _from_xml! 🙂)
  2. IDSIdentifier.alias didn't exist before this PR, no need to keep it for backwards compatibility
  3. Aliases / names are guaranteed to be unique -- this is checked in the Data Dictionary CI pipeline, so we don't need to check that when constructing the identifier
  4. I've added a test with custom identifier XML to test that multiple aliases works correctly

Thanks for the update @maarten-ic

Copy link
Collaborator

@maarten-ic maarten-ic left a comment

Choose a reason for hiding this comment

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

Code looks okay now.

My only reservation is that most tests are skipped now (because imas-data-dictionaries 4.1.0 is not yet released).
@olivhoenen how do you wish to proceed here? We could wait until DD4.1.0 is released before merging this PR, or test this again after 4.1.0 is released and fix any issues that may be present?

@olivhoenen olivhoenen self-requested a review October 16, 2025 19:04
@olivhoenen
Copy link
Collaborator

Code looks okay now.

My only reservation is that most tests are skipped now (because imas-data-dictionaries 4.1.0 is not yet released). @olivhoenen how do you wish to proceed here? We could wait until DD4.1.0 is released before merging this PR, or test this again after 4.1.0 is released and fix any issues that may be present?

Let's wait for 4.1.0, it shall come quickly now 🤞

False
>>> # Alias comparison example with materials identifier
>>> mid = imas.identifiers.materials_identifier
>>> materials = imas.IDSFactory().materials()
Copy link
Collaborator

Choose a reason for hiding this comment

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

materials ids is not present in the data dictionary. Could you use wall IDS which uses materials_indentfier.

print(f"Same object: {uranium235_by_name is uranium235_by_attr}")
# When assigning to IDS structures, any alias works the same way
materials = imas.IDSFactory().materials()
Copy link
Collaborator

Choose a reason for hiding this comment

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

materials ids is not present in the data dictionary. Could you use wall IDS which uses materials_indentfier.

mid = identifiers.materials_identifier

# Create an actual IDS structure
factory = IDSFactory("4.0.0").camera_x_rays()
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could also add example of identifiers where it is used an arrays. Aliases are just example I added for test

import imas
mid = imas.identifiers.materials_identifier
wallids = imas.IDSFactory().wall()
wallids.description_ggd.resize(1)
wallids.description_ggd[0].material.resize(1)
wallids.description_ggd[0].material[0].grid_subset.resize(1) 

names = wallids.description_ggd[0].material[0].grid_subset[0].identifiers.names
indices = wallids.description_ggd[0].material[0].grid_subset[0].identifiers.indices
descriptions = wallids.description_ggd[0].material[0].grid_subset[0].identifiers.descriptions

names.extend([""] * 5)
indices.resize(5)
descriptions.extend([""] * 5)
names[0]= mid["235U"].name
names[1]=  mid["238U"].name
names[2]=  mid["U_235"].name
names[3]= mid["67FGDFD"].name
names[4]= mid["GFHF34"].name

indices[0]= mid["235U"].index
indices[1]=  mid["238U"].index
indices[2]=  mid["U_235"].index
indices[3]= mid["67FGDFD"].index
indices[4]= mid["GFHF34"].index

descriptions[0]= mid["235U"].description
descriptions[1]=  mid["238U"].description
descriptions[2]=  mid["U_235"].description
descriptions[3]= mid["67FGDFD"].description
descriptions[4]= mid["GFHF34"].description
imas.util.inspect(wallids.description_ggd[0].material[0].grid_subset[0].identifiers)

# Test equality with canonical name
factory1 = IDSFactory("4.0.0").camera_x_rays()
mat1 = factory1.filter_window.material
mat1.name = "235U"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should assignment come from identifiers and assert later?

mat1.name = mid.U_235.name
mat1.index = mid.U_235.index
mat1.description = mid.U_235.description

print(csid.total.description)
# Access identifiers with aliases (when available)
mid = imas.identifiers.materials_identifier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we always use name attribute? In the IDS it stored as str('materials_identifier.235U')

import imas
mid = imas.identifiers.materials_identifier
factory2 = imas.IDSFactory().camera_x_rays()
mat2 = factory2.filter_window.material
mat2.name = mid.U_235 # Should we always use name attribute?
mat2.index = mid.U_235.index
mat2.description = mid.U_235.description
imas.util.inspect(mat2)

╭───── IDS structure: filter_window/material (DD version 4.0.1.dev324+g5180c8270.d20251021) ──────╮
│ Material of the filter window                                                                   │
│ ╭──────────────────────────────────────── Attributes ─────────────────────────────────────────╮ │
│ │ has_value = True                                                                            │ │
│ │  metadata = <IDSMetadata for 'material'>                                                    │ │
│ ╰─────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ ╭──────────────────────────────────────── Child nodes ────────────────────────────────────────╮ │
│ │ description = <IDSString0D (IDS:camera_x_rays, filter_window/material/description, STR_0D)> │ │
│ │               str('Uranium 235 isotope')                                                    │ │
│ │       index = <IDSInt0D (IDS:camera_x_rays, filter_window/material/index, INT_0D)>          │ │
│ │               int(20)                                                                       │ │
│ │        name = <IDSString0D (IDS:camera_x_rays, filter_window/material/name, STR_0D)>        │ │
│ │               str('materials_identifier.235U')                                              │ │
│ ╰─────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰─────────────────────────────────────────────────────────────────────────────────────────────────╯

core_sources.source[0].identifier = 1
# Identifiers can still be assigned with the old alias name for backward compatibility:
materials = imas.IDSFactory().materials()
Copy link
Collaborator

Choose a reason for hiding this comment

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

materials ids is not present in the data dictionary. Could you use wall IDS which uses materials_indentfier.

# Create an actual IDS structure
factory = IDSFactory("4.0.0").camera_x_rays()
mat = factory.filter_window.material
mat.name = "235U"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we add setter methods for setting name, index and description ?
for example
set_identifier("camera_x_rays.filter_window.material", "235U")
set_identifiers(wall.description_ggd[0].material[0].grid_subset[0].identifiers.names, ["235U", "U_238"]

Copy link
Collaborator

Choose a reason for hiding this comment

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

This already exists by assigning to the structure instead of a specific name/description/index node: https://imas-python.readthedocs.io/en/stable/identifiers.html#assigning-identifiers-in-imas-python

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it, thanks

For array of identifiers like this, do we need to use like this?
https://github.com/iterorganization/IMAS-Python/pull/77/files/ce507975c8fc1937d6e4507bdb7826cfc14197c6#r2448137366

wall.description_ggd[0].material[0].grid_subset[0].identifiers

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is the only place in the DD that has an array of identifiers, and it's not used in any ITER dataset at the moment.

Unless there's a good use case, I wouldn't really bother to implement something for arrays of identifiers 🙂

Copy link
Collaborator

Choose a reason for hiding this comment

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

There are a few SOLPS cases that are currently handled within the Fortran code. For now, we’ll wait until there is a use case to use it in the Python code.

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.

Take into account identifier aliases

4 participants