Madspin doesn't save and load pickle file properly for recent MG5v3
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MadGraph5_aMC@NLO |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
When we use the recent MG5v33x versions, we find Madspin cannot run properly from a pickle file. The error reads
Traceback (most recent call last):
File "/data/
cmd_
File "/data/
self.
File "/data/
stop = Cmd.onecmd_
File "/data/
return func(arg, **opt)
File "/data/
out = f(self, *args, **opt)
File "/data/
return self.run_
File "/data/
d['
TypeError: eval() arg 1 must be a string, bytes or code object
However, it runs successfully with on-the-fly usages. After looking into the codes, we find out that this bug comes from the improper treatment for pickle save and load part. In which the 'decay_struct' dictionaries are converted to strings when saving pickle file and convert back when loading. This leads to the bug mentioned above.
Now after commenting out the corresponding lines MadSpin works properly with saved pickle files. Changes are listed below:
--- a/MadSpin/decay.py
+++ b/MadSpin/decay.py
@@ -2181,9 +2181,9 @@ class decay_all_
modelpath = model.get(
- for me in self.all_ME:
- for d in self.all_
- d['decay_struct'] = str(d['
+ #for me in self.all_ME:
+ # for d in self.all_
+ # d['decay_struct'] = str(d['
--- a/MadSpin/
+++ b/MadSpin/
@@ -713,9 +713,9 @@ class MadSpinInterfac
#restore data passed to string to help pickle
- for me in generate_
- for d in generate_
- d['decay_struct'] = eval(d[
+ #for me in generate_
+ # for d in generate_
+ # d['decay_struct'] = eval(d[
# Re-create information which are not save in the pickle.
Changed in mg5amcnlo: | |
status: | Fix Committed → Fix Released |
Then this depend of the madspin_card that you use, since the linearisation of that dictionary can sometimes lead to crash and that was the reason of such patch.
The real question is why "decay_struct" is not a string when set like one...
Are you using the spinmode only mode of madspin?
Cheers,
Olivier
> On 23 Dec 2021, at 08:04, Sitian Qian <email address hidden> wrote: bond/stqian/ reproduce_ MG5331/ MG5_aMC_ v3_3_1/ bin/test_ ttbar/Events/ run_01/ ../../. ./../MadSpin/ madspin" , line 139, in <module> import_ command_ file(input_ file) bond/stqian/ reproduce_ MG5331/ MG5_aMC_ v3_3_1/ madgraph/ interface/ extended_ cmd.py" , line 1692, in import_command_file bond/stqian/ reproduce_ MG5331/ MG5_aMC_ v3_3_1/ madgraph/ interface/ extended_ cmd.py" , line 1573, in exec_cmd orig(current_ interface, line, **opt) bond/stqian/ reproduce_ MG5331/ MG5_aMC_ v3_3_1/ madgraph/ interface/ extended_ cmd.py" , line 1493, in onecmd_orig bond/stqian/ reproduce_ MG5331/ MG5_aMC_ v3_3_1/ madgraph/ various/ misc.py" , line 110, in f_with_no_logger bond/stqian/ reproduce_ MG5331/ MG5_aMC_ v3_3_1/ MadSpin/ interface_ madspin. py", line 621, in do_launch from_pickle( ) bond/stqian/ reproduce_ MG5331/ MG5_aMC_ v3_3_1/ MadSpin/ interface_ madspin. py", line 718, in run_from_pickle 'decay_ struct' ]) events( object) : estimator, bkp3 = self.width_ estimator, self.width_ estimator 'modelpath' ) ME[me][ 'decays' ]: decay_struct' ]) ME[me][ 'decays' ]: decay_struct' ]) interface_ madspin. py interface_ madspin. py e(extended_ cmd.Cmd) : all.all_ decay = eval(generate_ all.all_ decay) all.all_ ME:
>
> Public bug reported:
>
> When we use the recent MG5v33x versions, we find Madspin cannot run
> properly from a pickle file. The error reads
>
> Traceback (most recent call last):
> File "/data/
> cmd_line.
> File "/data/
> self.exec_cmd(line, precmd=True)
> File "/data/
> stop = Cmd.onecmd_
> File "/data/
> return func(arg, **opt)
> File "/data/
> out = f(self, *args, **opt)
> File "/data/
> return self.run_
> File "/data/
> d['decay_struct'] = eval(d[
> TypeError: eval() arg 1 must be a string, bytes or code object
>
> However, it runs successfully with on-the-fly usages. After looking into
> the codes, we find out that this bug comes from the improper treatment
> for pickle save and load part. In which the 'decay_struct' dictionaries
> are converted to strings when saving pickle file and convert back when
> loading. This leads to the bug mentioned above.
>
> Now after commenting out the corresponding lines MadSpin works properly
> with saved pickle files. Changes are listed below:
>
> --- a/MadSpin/decay.py
> +++ b/MadSpin/decay.py
> @@ -2181,9 +2181,9 @@ class decay_all_
> #self.all_ME, bkp2 = None , self.all_ME
> #self.width_
> modelpath = model.get(
> - for me in self.all_ME:
> - for d in self.all_
> - d['decay_struct'] = str(d['
> + #for me in self.all_ME:
> + # for d in self.all_
> + # d['decay_struct'] = str(d['
> self.modelpath = modelpath
>
>
> --- a/MadSpin/
> +++ b/MadSpin/
> @@ -713,9 +713,9 @@ class MadSpinInterfac
>
> #restore data passed to string to help pickle
> generate_
> - for me in generate_
> -...