Skip to content

Missing initialization handling #474

Description

@guidoagapito

Description
When specula.init() is not called before creating SPECULA objects, the global variables global_precision and default_target_device_idx remain None.
This causes issues when initializing BaseTimeObj and any objects that inherit from it.

Current Behavior
If specula.init() is not called, objects can be created but may behave unexpectedly or fail with confusing errors.
The uninitialized state is not caught early, leading to difficult debugging.

Proposed Solution
A warning is issued when BaseTimeObj detects uninitialized globals, and it falls back to safe defaults (CPU device with single precision).

Alternative Approaches
Raise an error (stricter): Force users to explicitly call specula.init() before creating any objects.

@alfiopuglisi and @FabioRossiArcetri:
Should we maintain the current warning approach or switch to raising a RuntimeError to enforce explicit initialization?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions