Skip to content

Ensure that secondary/tertiary stratum IDs are not being saved as 0#33

Merged
katieb1 merged 8 commits intomainfrom
kb-fix-output-stratum-state
Jun 19, 2025
Merged

Ensure that secondary/tertiary stratum IDs are not being saved as 0#33
katieb1 merged 8 commits intomainfrom
kb-fix-output-stratum-state

Conversation

@katieb1
Copy link
Member

@katieb1 katieb1 commented Jun 13, 2025

This PR fixes a bug that resulted in some rows of the Output Stratum State datasheet containing 0s instead of NULLs for the secondary and tertiary stratum IDs. These IDs get saved as 0 when the primary stratum in the row does not exist in the initial conditions distribution, but there are still transition pathways defined for the primary stratum. The IDs being 0 results in the following error when trying to export the datasheet from the command line (and consequently rsyncrosim and pysyncrosim):

The validation table does not contain the specified value.

@katieb1
Copy link
Member Author

katieb1 commented Jun 13, 2025

I also feel like this solution is maybe not complete as rows with primary stratum not in the initial conditions should probably not be included in the output stratum state datasheet at all. Also the min/max age is being reported as 0, where they should be NULL. These issues don't really have an effect on the final output, other than taking up disk space so I didn't fix them in this PR in the interest of time, but let me know if you think it's worth fixing.

@katieb1 katieb1 requested review from alexembrey and Copilot June 13, 2025 18:43
Copy link
Contributor

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 refactors how secondary and tertiary stratum IDs are collected and used when writing summary state data, moving from integer dictionaries to nullable lists and introducing null-coalescing proxies to avoid zero values being saved in output keys.

  • Replace CreateSecondary/TertiaryStratumDictionary with methods returning List<int?>
  • Iterate over int? lists and introduce ssProxy/tsProxy via ?? instead of raw zero
  • Update lookup key construction to use nullable proxies

katieb1 and others added 2 commits June 13, 2025 15:28
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Collaborator

@alexembrey alexembrey left a comment

Choose a reason for hiding this comment

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

I think that maybe all that needs to be done is something like this on line 1650:

OutputStratumState oss = new OutputStratumState(
dt.StratumIdSource,
ss == 0 ? null : ss,
ts == 0 ? null : ts,
iteration,
timestep,
dt.StateClassIdSource,
0, 0, 0, 0.0);

This would avoid the changes from Dictionary to List which will make things slower.

@katieb1
Copy link
Member Author

katieb1 commented Jun 17, 2025

@alexembrey I made the requested changes to keep the dictionaries (although I had to do it slightly differently because it wouldn't let me directly convert ss and ts to null).

@katieb1 katieb1 requested a review from alexembrey June 17, 2025 18:25
Copy link
Collaborator

@alexembrey alexembrey left a comment

Choose a reason for hiding this comment

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

The new code looks good to me, so if it fixes the problem in testing then I think all is well.

@katieb1 katieb1 merged commit 5161819 into main Jun 19, 2025
@katieb1 katieb1 deleted the kb-fix-output-stratum-state branch June 19, 2025 16:50
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.

3 participants