Skip to content

Broken-alpha: Genpdf snvar conditioning#1639

Open
trivialTZ wants to merge 5 commits intoRickKessler:masterfrom
trivialTZ:genpdf-snvar-conditioning
Open

Broken-alpha: Genpdf snvar conditioning#1639
trivialTZ wants to merge 5 commits intoRickKessler:masterfrom
trivialTZ:genpdf-snvar-conditioning

Conversation

@trivialTZ
Copy link
Copy Markdown
Collaborator

Extends GENPDF map conditioning so that extra dimensions can reference SN-generated variables (SALT2x1, SALT2c, RV, AV) in addition to HOSTLIB columns. This enables simulation of x1-dependent alpha distributions (broken-alpha) via GENPDF maps.

Changes:

  • Add PTRVAL_SNVAR and USE_HOSTLIB fields to GENPDF struct
  • Fall back to checkSNvar_HOSTLIB_WGTMAP() when HOSTLIB lookup fails
  • Raise MXROW_GENPDF from 15000 to 50000 for dense conditioning maps
  • Update funVal_genPDF and getRan_genPDF to read from SNVAR pointers

Build to achieve functionality for simulation similar to Ginolin et al. 2025 (ZTF DR2) broken-alpha finding.

Code changes

1. New struct fields (sntools_genPDF.h)

double *PTRVAL_SNVAR[MXVAR_GENPDF];  // pointer to live SN value (e.g., &GENLC.SALT2x1)
bool    USE_HOSTLIB[MXVAR_GENPDF];   // true=HOSTLIB lookup, false=SNVAR dereference

Each conditioning dimension of a GENPDF map now tracks which source to read from at runtime and, for SNVARs, stores a direct pointer to the simulator's internal value.

Also raised MXROW_GENPDF from 15000 to 50000 to support dense 2D maps (e.g., a fine alpha-vs-x1 grid can easily require 10k+ rows).

2. Safe initialization (two sites)

Both init_genPDF() (file-based maps) and init_genPDF_from_GenGauss() (Gaussian maps) now initialize the new fields:

for(ivar=0; ivar < MXVAR_GENPDF; ivar++) {
    GENPDF[NMAP].IVAR_HOSTLIB[ivar] = -9;
    GENPDF[NMAP].PTRVAL_SNVAR[ivar] = NULL;
    GENPDF[NMAP].USE_HOSTLIB[ivar]  = true;   // default: HOSTLIB
}

Defaults ensure backward compatibility: existing maps that only use HOSTLIB variables are unaffected.

3. Variable resolution with SNVAR fallback (init_genPDF)

The init-time loop that validates conditioning variables is changed from a single HOSTLIB-or-crash lookup to a three-step fallback:

Before:

for each conditioning variable:
    look up in HOSTLIB → not found? FATAL error

After:

for each conditioning variable:
    1. Try HOSTLIB lookup → found? store IVAR, set USE_HOSTLIB=true, done
    2. Try checkSNvar_HOSTLIB_WGTMAP() → recognized? store pointer, set USE_HOSTLIB=false, done
    3. Neither → FATAL error (with updated message mentioning both sources)

Step 2 reuses the existing upstream function checkSNvar_HOSTLIB_WGTMAP() (in sntools_host.c) which maps variable names to live pointers:

  • "SALT2x1" / "x1"GENLC.ptr_SHAPEPAR
  • "SALT2c" / "c"&GENLC.SALT2c
  • "AV"&GENLC.AV
  • "RV"&GENLC.RV

4. Runtime value retrieval (three sites)

Three functions that read conditioning values during simulation are updated with the same if/else pattern:

  • funVal_genPDF() — evaluates P(x | conditions)
  • getRan_genPDF() — accept/reject random draw, sets up conditioning values
  • Debug dump in getRan_genPDF() — prints conditioning values when LDMP is on

Before (all three):

for(ivar=1; ivar < NDIM; ivar++) {
    IVAR_HOSTLIB = GENPDF[IMAP].IVAR_HOSTLIB[ivar];
    xval[ivar]   = get_VALUE_HOSTLIB(IVAR_HOSTLIB, IGAL);
}

After (all three):

for(ivar=1; ivar < NDIM; ivar++) {
    if (GENPDF[IMAP].USE_HOSTLIB[ivar]) {
        IVAR_HOSTLIB = GENPDF[IMAP].IVAR_HOSTLIB[ivar];
        xval[ivar]   = get_VALUE_HOSTLIB(IVAR_HOSTLIB, IGAL);
    } else {
        PTR_SNVAR = GENPDF[IMAP].PTRVAL_SNVAR[ivar];
        // NULL safety check with SEV_FATAL
        xval[ivar] = *PTR_SNVAR;
    }
}

Usage: simulating broken-alpha

Step 1: Write a GENPDF map file

The map defines P(SALT2ALPHA | SALT2x1). The first column is the generated parameter, middle columns are conditioning variables, and the last column is probability.

Minimal example (genpdf_alpha_vs_x1.DAT):

VARNAMES: SALT2ALPHA  SALT2x1  PROB
PDF: 0.11  -3.0  1.00
PDF: 0.19  -3.0  0.08
PDF: 0.11  -1.5  1.00
PDF: 0.19  -1.5  0.20
PDF: 0.11   0.0  1.00
PDF: 0.19   0.0  1.00
PDF: 0.11   1.5  0.20
PDF: 0.19   1.5  1.00
PDF: 0.11   3.0  0.08
PDF: 0.19   3.0  1.00

This encodes: at low x1 (x1=-3), alpha around 0.11 is strongly preferred; at high x1 (x1=+3), alpha~0.19 is preferred (broken-alpha population)

For precision studies (e.g., hard break at a specific x1), use a dense grid. Example with Ginolin+2024 truth values (alpha_low=0.280, alpha_high=0.088, break at x1=-0.49):

VARNAMES: SALT2ALPHA  SALT2x1  PROB
PDF: 0.088  -4.000  0.000
PDF: 0.091  -4.000  0.000
...
PDF: 0.280  -4.000  1.000
PDF: 0.088  -3.960  0.000
...

Dense maps require MXROW_GENPDF >= 50000 (included in this PR).

Step 2: Reference the map in snlc_sim input

GENMODEL:  SALT3.K21

GENPDF_FILE:    /path/to/genpdf_alpha_vs_x1.DAT
GENPDF_OPTMASK: 1

GENPEAK_SALT2x1:   0.0
GENSIGMA_SALT2x1:  1.0  1.0
GENRANGE_SALT2x1:  -3.0  3.0

Important: The x1 distribution (GENPEAK/GENSIGMA/GENRANGE_SALT2x1) must be defined so that x1 is generated first; the GENPDF map then draws alpha conditioned on the already-generated x1 value.

Step 3: Verify in the log

On successful init, snlc_sim prints:

Check GENPDF conditioning variables (HOSTLIB or SNVAR):
    Found SNVAR pointer for VARNAME='SALT2x1' (SALT2ALPHA)
    Found 0 HOSTLIB vars and 1 SNVARs in GENPDF map SALT2ALPHA

Pippin YAML example

SIM:
  BROKEN_ALPHA:
    IA:
      BASE: sim_broken_alpha.input   # references GENPDF_FILE above
    GLOBAL:
      NGEN_UNIT: 1
      BATCH_INFO: sbatch $SBATCH_TEMPLATES/SBATCH_LOCAL.TEMPLATE 1

trivialTZ and others added 2 commits April 9, 2026 21:31
Extends GENPDF map conditioning so that extra dimensions can reference
SN-generated variables (SALT2x1, SALT2c, RV, AV) in addition to HOSTLIB
columns. This enables simulation of x1-dependent alpha distributions
(broken-alpha) via GENPDF maps.

Changes:
- Add PTRVAL_SNVAR and USE_HOSTLIB fields to GENPDF struct
- Fall back to checkSNvar_HOSTLIB_WGTMAP() when HOSTLIB lookup fails
- Raise MXROW_GENPDF from 15000 to 50000 for dense conditioning maps
- Update funVal_genPDF and getRan_genPDF to read from SNVAR pointers

Motivated by Ginolin et al. 2025 (ZTF DR2) broken-alpha finding.
char string[40] overflows when MAPSIZE >= ~1000 because the formatted
string "allocate %.2f MB for %d bins and NFUN=%d" can reach 49 bytes.
Widen to 100.

This caused a __chk_fail_overflow crash (SIGTRAP) when loading dense
GENPDF maps with >10k rows.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@trivialTZ trivialTZ changed the title Genpdf snvar conditioning Broken-alpha: Genpdf snvar conditioning Apr 10, 2026
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.

1 participant