Skip to content

Sheshuk/update flavor matrix interface#350

Merged
sybenzvi merged 19 commits into
release_v2.0from
Sheshuk/update_FlavorMatrix_interface
Aug 13, 2024
Merged

Sheshuk/update flavor matrix interface#350
sybenzvi merged 19 commits into
release_v2.0from
Sheshuk/update_FlavorMatrix_interface

Conversation

@Sheshuk

@Sheshuk Sheshuk commented Aug 1, 2024

Copy link
Copy Markdown
Contributor

This is a first part of changes, needed for #344

Expanding the interface of FlavorScheme and FlavorMatrix with useful methods and syntactic sugar. The goal is to make the code using these classes more expressive and look more similar to the formulas in the papers.

Example

This allows us to access and define individual matrix elements as well as whole submatrices with a clear interface (example from #344 defining the elements of matrix in mass_basis<<flavor_basis space)

# The NMO case. Matter state 3 is the electron neutrino, matter state 1bar is the electron antineutrino.
k1 = T - np.sqrt(D)
k2 = T + np.sqrt(D)
k2bar = Tbar - np.sqrt(Dbar)
k3bar = Tbar + np.sqrt(Dbar)
PmfHDL['1','mu'] = (HV['tau','tau'].real - k1)/(k2-k1)
PmfHDL['1','tau'] = (HV['mu','mu'].real - k1)/(k2-k1)
PmfHDL['2','mu'] = (HV['tau','tau'].real - k2)/(k1-k2)
PmfHDL['2','tau'] = (HV['mu','mu'].real - k2)/(k1 -k2)
PmfHDL['3','e'] = 1
PmfHDL['1_bar','e_bar'] = 1
PmfHDL['2_bar','mu_bar'] = (HV['tau_bar','tau_bar'].real - k2bar ) / ( k3bar - k2bar )
PmfHDL['2_bar','tau_bar'] = (HV['mu_bar','mu_bar'].real - k2bar ) / ( k3bar - k2bar )
PmfHDL['3_bar','mu_bar'] = (HV['tau_bar','tau_bar'].real - k3bar ) / ( k2bar - k3bar )
PmfHDL['3_bar','tau_bar'] = (HV['mu_bar','mu_bar'].real - k3bar ) / ( k2bar - k3bar )

Changes in FlavorScheme

  1. Allowing to use shorter names for neutrinos, omitting NU_ prefix. Also ignoring the case.
  2. Adding the 'NU' and 'NU_BAR' names to access the list of all neutrinos or antineutrinos

Changes in FlavorMatrix

  1. Useful methods for complex matrix: real,imag,abs, abs2, conjugate
  2. In the __matmul__ method: added check if the flavor schemes of the matrices' dimensions are compatible.
  3. Adding the extra_dims options to constructors FlavorMatrix.eye and FlavorMatrix.zeros - to initialize arrays of size (N x M x extra_dims). These extra dimensions can be energy and/or time dependency of the transformation
  4. Added conversion methods: convert_to_flavor method, and also << and >> operators, which allows to do the flavor bases conversion in one line, for example M_3f = (ThreeFlavor<<M<<ThreeFlavor)
  5. Using np.einsum to perform the correct matrix multiplication of the matrices and matrix to flux
  6. When creating conversion matrix, for example(ThreeFlavor<<FourFlavor), it will check that the matrix is non-zero - to prevent silent zeroing out when there was an intrinsic conversion to an incompatible flavor scheme

See the changes in test/test_flavors.py for the demonstration of some new functionality

@Sheshuk Sheshuk marked this pull request as ready for review August 1, 2024 14:41
@sybenzvi

Copy link
Copy Markdown
Contributor

Integration tests are failing because of this obsolete flavor transformation (line 152 of base.py) in the SupernovaModel base class.

@sybenzvi sybenzvi self-requested a review August 13, 2024 15:45
Comment thread python/snewpy/flavor.py Outdated

@sybenzvi sybenzvi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: while we have this PR open, rename the EnumMeta child class in flavor.py toFlavorEnumMeta.

Otherwise this looks pretty good.

@sybenzvi

sybenzvi commented Aug 13, 2024

Copy link
Copy Markdown
Contributor

Integration tests are failing because of this obsolete flavor transformation (line 152 of base.py) in the SupernovaModel base class.

After discussion on Zoom, we agree that the failing integration tests are all due to the obsolete code in get_transformed_spectra that will be not be addressed until PR #351. So this should not hold up the merge.

@sybenzvi sybenzvi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I made a cosmetic change of snewpy.flavor.EnumMeta to snewpy.flavor.FlavorEnumMeta, which feels a bit safer. Otherwise we can commit this, with the understanding that integration tests will fail in release_2.0.

@sybenzvi sybenzvi merged commit 1cd1abc into release_v2.0 Aug 13, 2024
@sybenzvi sybenzvi deleted the Sheshuk/update_FlavorMatrix_interface branch August 13, 2024 16:51
@sybenzvi sybenzvi restored the Sheshuk/update_FlavorMatrix_interface branch August 15, 2024 19:08
sybenzvi pushed a commit that referenced this pull request Aug 15, 2024
@Sheshuk Sheshuk deleted the Sheshuk/update_FlavorMatrix_interface branch December 6, 2024 13:50
JostMigenda pushed a commit that referenced this pull request Apr 29, 2025
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.

2 participants