Skip to content

Support int64 seeds in MalariaConfig.from_params() #39

@edwenger

Description

@edwenger

Problem

When using create_config() with large seed values (> 2^31), the pybind11 bindings fail with:

RuntimeError: Unable to cast Python instance of type <class 'int'> to C++ type '?'

This occurs in MalariaConfig.from_params(merged) when Run_Number exceeds the int32 range.

Reproduction

from emodlib.malaria import create_config                                                                                                           
                                                                                                                                                     
 # Works (fits in int32)                                                                                                                             
 config = create_config({'Run_Number': 368693116})                                                                                                   
                                                                                                                                                     
 # Fails (exceeds int32 max of 2147483647)                                                                                                           
 config = create_config({'Run_Number': 2191622255})      

Current Workaround

In the mops-examples/emodlib-demo, we're truncating seeds to fit int32:

  params_dict = {                                                                                                                                     
      'Run_Number': int(seed) % (2**31),  # Workaround for int32 limit                                                                                
      ...                                                                                                                                             
  }          

This works but loses entropy from the full 64-bit seed space that modelops provides.

Suggested Fix

Update the C++ bindings to accept int64 for Run_Number, or add explicit type conversion/validation in the Python create_config() wrapper with a clear error message.

Context

  • Discovered while running emodlib-demo on modelops k8s cluster (only on larger sweeps that didn't get lucky and always have smaller random seeds)
  • The modelops framework generates random seeds as large integers (up to ~4 billion)
  • See commit edwenger/mops-examples@526c3c7 for the workaround

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions