Skip to content

HashPRNG (stdnormal) gives different values in different architectures #287

@ikrommyd

Description

@ikrommyd

This correction which is a random number generator correction
Image
gives different values on different architectures. It appears that it's only stdnormal while stdflat is fine.
Arm64:

In [49]: x.layout
Out[49]:
<RecordArray length="25">
    <field index="0" key="pt">
        <NumpyArray format="f" shape="25" data="29.56 60.0685 51.705 10.6553 8.59726 ... 26.9614 28.5527 36.3018 15.607 7.67689" at="0x600000cc7950"/>
    </field>
    <field index="1" key="r9">
        <NumpyArray format="f" shape="25" data="0.881836 0.879883 0.889648 0.997559 0.95752 ... 0.82373 0.672852 0.939453 0.981934 0.874512" at="0x600000cc79c0"/>
    </field>
    <field index="2" key="eta">
        <NumpyArray format="f" shape="25" data="1.83179 -0.292542 -0.904053 -2.18555 1.64502 ... -1.76221 0.784546 2.02441 -0.0594559 0.38092" at="0x600000cc72c0"/>
    </field>
    <field index="3" key="event">
        <NumpyArray format="L" shape="25" data="3749762 3749777 3749777 3749768 3749768 ... 3749856 3749862 3749861 3749875 3749883" at="0x600001ce5ba0"/>
    </field>
</RecordArray>

In [50]: rng.evaluate("stdnormal", x.pt, x.r9, x.eta, x.event)
Out[50]:
array([-0.26883039,  0.28672353, -0.57431689,  2.63626883, -0.83464608,
        0.90847055,  0.45283389, -0.41724338,  0.30672475,  0.60342825,
       -1.5795927 , -0.89867654, -1.61526027, -0.54997331, -0.00784177,
        2.00220383,  1.21941401, -0.36870525,  0.50568698,  0.28755395,
       -0.94606972,  2.23859349,  1.80704412, -1.85895929,  0.69082279])

In [51]:

In [51]: rng.evaluate("stdflat", x.pt, x.r9, x.eta, x.event)
Out[51]:
array([0.93352256, 0.87892313, 0.78439512, 0.12686755, 0.46446161,
       0.05117117, 0.46069956, 0.99490182, 0.49302054, 0.25524578,
       0.00626383, 0.50793706, 0.18885202, 0.93374629, 0.95984817,
       0.21819859, 0.77767419, 0.90941815, 0.82405071, 0.66864401,
       0.30018088, 0.69552463, 0.88240465, 0.85859066, 0.41470936])

In [52]: exit
(higgs-dna) ➜  ~ uname -m
arm64

versus x86:

In [14]: x.layout
Out[14]:
<RecordArray length="25">
    <field index="0" key="pt">
        <NumpyArray format="f" shape="25" data="29.56 60.0685 51.705 10.6553 8.59726 ... 26.9614 28.5527 36.3018 15.607 7.67689" at="0x55c8524d07c0"/>
    </field>
    <field index="1" key="r9">
        <NumpyArray format="f" shape="25" data="0.881836 0.879883 0.889648 0.997559 0.95752 ... 0.82373 0.672852 0.939453 0.981934 0.874512" at="0x55c8524d08d0"/>
    </field>
    <field index="2" key="eta">
        <NumpyArray format="f" shape="25" data="1.83179 -0.292542 -0.904053 -2.18555 1.64502 ... -1.76221 0.784546 2.02441 -0.0594559 0.38092" at="0x55c8521ee4a0"/>
    </field>
    <field index="3" key="event">
        <NumpyArray format="L" shape="25" data="3749762 3749777 3749777 3749768 3749768 ... 3749856 3749862 3749861 3749875 3749883" at="0x55c8522e6190"/>
    </field>
</RecordArray>

In [15]: rng.evaluate("stdnormal", x.pt, x.r9, x.eta, x.event)
Out[15]:
array([ 0.49944807,  1.39058204, -0.02216484, -0.08730098,  0.63380507,
       -0.74493107,  1.17528214, -1.06762684, -0.4320127 , -0.93337605,
       -0.17058287,  0.63699673,  0.98020086, -0.44526196,  0.73744931,
       -0.09207296, -0.3074458 , -0.88816113,  1.80998704, -1.1880895 ,
       -2.18910314, -1.64921238,  0.60019342, -2.07503974,  0.15367366])

In [16]: rng.evaluate("stdflat", x.pt, x.r9, x.eta, x.event)
Out[16]:
array([0.93352256, 0.87892313, 0.78439512, 0.12686755, 0.46446161,
       0.05117117, 0.46069956, 0.99490182, 0.49302054, 0.25524578,
       0.00626383, 0.50793706, 0.18885202, 0.93374629, 0.95984817,
       0.21819859, 0.77767419, 0.90941815, 0.82405071, 0.66864401,
       0.30018088, 0.69552463, 0.88240465, 0.85859066, 0.41470936])

In [17]: exit
u%                                                                                                                                                                                                                                           (coffea_0.7.x) ➜  ~ uname -m
x86_64

I'm attaching the correction file
EGMScalesSmearing_Pho_2022postEE2G.v1.json.gz

and also here's how I created this pseudo array to test this from our favorite nano_dy.root file

import awkward as ak
import uproot
import correctionlib

events = uproot.open("work/coffea_dev/coffea/tests/samples/nano_dy.root")["Events"].arrays()
x = ak.flatten(ak.zip({"pt": events.Electron_pt, "r9": events.Electron_r9, "eta": events.Electron_eta, "event": events.event, "run": events.run}))

cset = correctionlib.CorrectionSet.from_file("EGMScalesSmearing_Pho_2022postEE2G.v1.json.gz")
rng = cset["EGMRandomGenerator"]
print(rng.evaluate("stdnormal", x.pt, x.r9, x.eta, x.event))
print(rng.evaluate("stdflat", x.pt, x.r9, x.eta, x.event))

Other corrections like

In [9]: cset["EGMScaleVsRun_2022postEE"].evaluate(x.run, x.eta)
Out[9]:
array([1.00814164, 1.01591229, 1.03152823, 1.01894987, 0.99801081,
       1.03152823, 1.01894987, 1.01591229, 1.02502155, 1.02363706,
       1.0188297 , 1.01591229, 1.02372885, 1.01894987, 1.01514328,
       1.01811612, 1.01514328, 1.02341413, 1.01591229, 1.01811612,
       1.0188297 , 1.01514328, 1.00814164, 1.01591229, 1.01289177])

are the same on both architectures

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingevaluatorIssues related to the evaluator

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions