1818from ..algorithms .codec import Decode
1919from ..algorithms .codec import Encode
2020from ..algorithms .randomize import Randomize
21+ from ..generators import DefaultGenerator
2122from ..interface .logging import Logging
2223from ..interface .operator import Operator
2324from ..logger import get_logger
@@ -90,6 +91,10 @@ def run(self, source: Dataset) -> Dataset: # noqa: D102
9091 :param source: The source dataset.
9192 :return: The result dataset.
9293 """
94+ source_id = source .attrs .get (
95+ "tracking_id" ,
96+ source .attrs .get ("uuid" , self ._args .source_file .stem ),
97+ )
9398 target = Dataset (
9499 data_vars = source .data_vars ,
95100 coords = source .coords ,
@@ -106,10 +111,9 @@ def run(self, source: Dataset) -> Dataset: # noqa: D102
106111
107112 a : dict [str :Any ] = config [v ]
108113 f = Randomize (
109- np .single ,
110- x .ndim ,
114+ m = x .ndim ,
111115 dist = a ["distribution" ],
112- entropy = self .entropy (v ),
116+ entropy = self .entropy (v , source_id ),
113117 )
114118 if "uncertainty" in a :
115119 u = (
@@ -179,15 +183,20 @@ def config(self) -> dict[str : dict[str:Any]]:
179183 config = json .load (r )
180184 return config
181185
182- def entropy (self , v : str ) -> list [int ]:
186+ def entropy (self , vid : str , did : str , n : int = 8 ) -> list [int ]:
183187 """
184188 Returns the entropy of the seed sequence used for a given variable.
185189
186- :param v: The name of the variable.
190+ Entropy is generated using the Philox bit generator, which produces
191+ truly independent sequences for different values of the seed.
192+
193+ :param vid: The variable ID.
194+ :param did: The dataset ID.
195+ :param n: The length of the seed sequence.
187196 :return: The entropy.
188197 """
189- return [
190- self . _args . selector ,
191- _hash (v ),
192- _hash ( self . _args . source_file . stem ),
193- ]
198+ from numpy . random import Philox
199+
200+ seed = _hash (f" { vid } - { did } " ) + self . _args . selector
201+ g = DefaultGenerator ( Philox ( seed ))
202+ return [ g . next () for _ in range ( n ) ]
0 commit comments