Skip to content

50.1 parameter workflow #133

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

Open
wants to merge 137 commits into
base: v2.0
Choose a base branch
from
Open

50.1 parameter workflow #133

wants to merge 137 commits into from

Conversation

along4
Copy link
Collaborator

@along4 along4 commented May 19, 2025

Working on parameter file manager to read in or write SAMMY parameter files based FitConfig objects.

This functionality with be based on creating a ParManager that will be passed a parameter file path and a FitConfig object.

Read functionality - Taking a parameter file and populating a given FitConfig object.

  • Read in and process isotope parameters (This is parameter card 10 with abundances, vary_flags, and spin_groups)
  • Read in and process resonance entries (This is parameter card 1 with energies, widths, and vary flags)
  • Read in and process Radii data
  • Read in normalization data
  • Read in background data
  • Read in Input Card 4 blocks, if present
  • Read in Input Card 10 blocks if present

Write functionality - Taking a given FitConfig object and writing a parameter file.

  • Write isotope parameters
  • Write radii data
  • Write resonance parameters
  • Write particle pair definitions
  • Write spin group definitions
  • Write normalization data
  • Write background data

Write unit tests for par_manager and card_formats.

  • inp04_particlepairs.py
  • inp10_spingroups.py
  • par01_resonances.py
  • par04_broadening.py
  • par06_normalization.py
  • par07_radii.py
  • par07a_radii.py
  • par10_isotopes.py

@along4 along4 self-assigned this May 19, 2025
@Copilot Copilot AI review requested due to automatic review settings May 19, 2025 03:35
@along4 along4 marked this pull request as draft May 19, 2025 03:35
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds support for reading and writing SAMMY parameter files via a new ParManager and migrates isotope parsing to a dedicated Card10 class.

  • Replaces legacy IsotopeCard with Card10 in tests and I/O code
  • Introduces ParManager for high-level parameter file operations
  • Updates models for optional isotope information and improves logging

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/pleiades/sammy/parameters/test_isotope.py Updated imports/tests to use Card10 instead of IsotopeCard
tests/unit/pleiades/sammy/io/test_par_manager.py Added placeholder file for ParManager unit tests
tests/unit/pleiades/sammy/io/card_formats/test_par10_isotopes.py New unit tests for Card10 parsing of isotope card
src/pleiades/sammy/parameters/isotope.py Removed deprecated IsotopeCard implementation
src/pleiades/sammy/parameters/init.py Dropped import of the removed isotope module
src/pleiades/sammy/io/par_manager.py Added ParManager class for managing SAMMY param file I/O
src/pleiades/sammy/io/card_formats/par10_isotopes.py Introduced Card10 for parsing/writing Card 10 entries
src/pleiades/nuclear/models.py Made isotope_information field optional in IsotopeParameters
src/pleiades/nuclear/isotopes/models.py Removed unused __str__ override
src/pleiades/nuclear/isotopes/manager.py Enhanced logging, fixed prints, and added isotope lookup
examples/samexm/ex012/ex012a.inp Added directive for quantum numbers in example input file
Comments suppressed due to low confidence (2)

src/pleiades/nuclear/isotopes/manager.py:123

  • Method name typo: get_istotpe_info_from_mass should be get_isotope_info_from_mass.
def get_istotpe_info_from_mass(self, mass: float) -> Optional[IsotopeInfo]:

tests/unit/pleiades/sammy/io/test_par_manager.py:1

  • Test file contains no actual test functions—add assertions for ParManager methods like extract_isotopes_and_abundances.
"""Unit tests for SAMMY parameter file classes."""

@along4 along4 marked this pull request as ready for review June 30, 2025 03:01
@along4 along4 requested a review from Copilot June 30, 2025 03:01
Copilot

This comment was marked as outdated.

@along4
Copy link
Collaborator Author

along4 commented Jun 30, 2025

Hey @KedoKudo, I was able to wrap up all the needed pytests for the parameter file io modules. Just submitted it for review.

@KedoKudo
Copy link
Collaborator

Hey @KedoKudo, I was able to wrap up all the needed pytests for the parameter file io modules. Just submitted it for review.

Thanks, I will start the review process

Copy link
Collaborator

@KedoKudo KedoKudo left a comment

Choose a reason for hiding this comment

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

Please take a look at the comments. We currently have mixed coding styles in the repo, and we will need to address that at some point (hopefully with 🤖 )

logger.error(message)
raise ValueError(message)

# if fit_config is not an instance of FitConfig, raise an error
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 a good advice, we only need to check fit_config once.

for line in content_lines:
# Check if the line has a continuation marker ("-1") at the end
# If it does, append the line to the current isotope group
if line.endswith("-1"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

A correctly formatted parameter files should not have white space after -1, but I think maybe adding rstrip() will make it more robust in case an extra space is added accidentally

Comment on lines 338 to 339
if fit_config.nuclear_params.isotopes is None:
logger.info(f"Isotpe list is empty, creating new isotope with mass {mass}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I recommend accepting this suggestion.

Comment on lines +368 to +372
line_key = line.strip()[:5].upper()
for header, card_enum in PAR_HEADER_MAP.items():
header_key = header.strip()[:5].upper()
if line_key == header_key:
found_cards.add(card_enum)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Feel free to ignore this one, we already know that SAMMY only check the first 5 char to identify card

…rd formats. Moved all imports to top of file
@along4 along4 requested a review from Copilot July 27, 2025 16:42
Copilot

This comment was marked as outdated.

@along4 along4 requested a review from Copilot July 28, 2025 22:32
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a comprehensive parameter file manager for SAMMY with complete read/write functionality for handling SAMMY parameter files based on FitConfig objects. The implementation includes reading and writing capabilities for various parameter cards including resonance entries, isotope parameters, radius data, normalization data, background data, particle pair definitions, and spin group definitions.

Key changes include:

  • Implementing ParManager class for handling SAMMY parameter file I/O operations
  • Creating modular card format parsers for different parameter types (par01-par10, inp04, inp10)
  • Replacing the legacy isotope parameter handling with new card-based approach
  • Adding comprehensive unit tests for all card formats and the parameter manager

Reviewed Changes

Copilot reviewed 36 out of 38 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/unit/pleiades/sammy/test_parfile.py Removed legacy parameter file test module
tests/unit/pleiades/sammy/parameters/test_isotope.py Updated imports to use new card format classes
tests/unit/pleiades/sammy/io/test_par_manager.py Added comprehensive tests for ParManager functionality
tests/unit/pleiades/sammy/io/card_formats/ Added unit tests for all card format parsers
tests/unit/pleiades/nuclear/test_nuclear_models.py Updated to use new SpinGroups and SpinGroupChannels models
src/pleiades/utils/helper.py Added pseudo-scientific notation parser for SAMMY files
src/pleiades/sammy/parameters/ Removed legacy isotope parameter handling
src/pleiades/sammy/io/par_manager.py Added main ParManager class for parameter file operations
src/pleiades/sammy/io/card_formats/ Added modular card format parsers for different parameter types

Comment on lines +241 to +242
# self.assertEqual(params.isotopes[0].resonances, [resonance_entry])
# self.assertEqual(params.isotopes[0].radius_parameters, [radius_params])
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

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

Commented-out assertions should be removed or uncommented with proper implementation. These dead code comments reduce code clarity and should be cleaned up.

Suggested change
# self.assertEqual(params.isotopes[0].resonances, [resonance_entry])
# self.assertEqual(params.isotopes[0].radius_parameters, [radius_params])
self.assertEqual(params.isotopes[0].resonances, [resonance_entry])
self.assertEqual(params.isotopes[0].radius_parameters, [radius_params])

Copilot uses AI. Check for mistakes.

for channel in channels:
lines.append(f" Chan= {channel:2d},")

# Remove trailing blank lines (but keep one at end)
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

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

[nitpick] The comment mentions removing trailing blank lines but keeping one at the end, however the implementation removes all trailing blank lines and then adds one. Consider clarifying the comment to match the implementation.

Suggested change
# Remove trailing blank lines (but keep one at end)
# Remove all trailing blank lines and then add one to ensure exactly one blank line at the end

Copilot uses AI. Check for mistakes.

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

Successfully merging this pull request may close these issues.

3 participants