loop matrix element through python

Asked by Mohammad on 2019-03-22

Dear Madgraph experts,

I'm trying to calculate matrix elements using the python interface as in https://cp3.irmp.ucl.ac.be/projects/madgraph/wiki/FAQ-General-4, but for loop amplitudes.
I'm using the loop_sm model and I'm working with the u u~ > z > t t~ process.
This is what I'm doing:

import model loop_sm
generate u u~ > z > t t~ [virt=QCD]
output test_virtual (I also tried : output standalone test_virtual)
launch

then, after entering the process library P0_uux_z_ttx I'm doing the following:

make matrix2py.so

which creates check_sa.py. Then when doing: ./check_sa.py or python check_sa.py I get this error:

Traceback (most recent call last):
  File "check_sa.py", line 47, in <module>
    matrix2py.ml5_0_initialise(os.path.abspath(pjoin(root_path,os.pardir,os.pardir,'Cards','param_card.dat')))
AttributeError: 'module' object has no attribute 'ml5_0_initialise'

I also tried to run it through a python script as in https://cp3.irmp.ucl.ac.be/projects/madgraph/wiki/FAQ-General-4, but I got this error:

Traceback (most recent call last):
  File "MG5-PBZp-comparison.py", line 26, in <module>
    matrix2py.initialisemodel('../../Cards/param_card.dat')
AttributeError: 'module' object has no attribute 'initialisemodel'

PS: I tested this procedure for LO processes in the sm model file and it works fine.

Thank you in advance,
Best,
Mohammad

Question information

Language:
English Edit question
Status:
Open
For:
MadGraph5_aMC@NLO Edit question
Assignee:
Valentin Hirschi Edit question
Last query:
2019-04-03
Last reply:

PS: I was using version 2_6_4

I have the same problem also with version 2_6_5

Hi,

For Valentin sake,
I can reproduce the issue.

I have also found that the following two functions are defined:

./SubProcesses/P0_uux_z_ttx/born_matrix.f:366: SUBROUTINE ML5_0_INITIALISEMODEL(PATH)
Binary file ./SubProcesses/P0_uux_z_ttx/born_matrix.o matches
./SubProcesses/P0_uux_z_ttx/f2py_wrapper.f:1: SUBROUTINE INITIALISE(PATH)

In order to make it trough, I had to change check_sa.py to use the following:
# Read the model parameters
matrix2py.initialise(os.path.abspath(pjoin(root_path,os.pardir,os.pardir,'Cards','param_card.dat')))
This can be in prinicple be changed in
./iolibs/template_files/loop_optimized/check_sa.py.inc

But I guess this is too naive... What do you think Valentin?

Cheers,

Olivier

Dear Mohammad,

For the sake of other users, I am copying here my email replies to your direct queries sent to me:

My reply A:

----
The prefixes of the python binding functions such as `ml5_0_initialise` used in the script `.\check_sa.py` are unfoturnately not up to date.
I should fix this.
You can easily check what is the correct prefix and adjust it in the script `check_sa.py` by doing:

```
python
import matrix2py
print dir(matrix2py)
```

and it should show all functions exposed in the python bindings, so you can recognise and adjust the correct index.
I will try to fix this soon.

Alternatively and in the meantime you can also simply use the fortran driver with
```
make check
./check
```

You can adjust things (PS point evaluated for instance) directly in the fortran driver file `check_sa.f`
----

Your request B:

----
Thank you very much for your answer, this solved my problem.
The reason why I want to use python is that I'm using other tools to compare with madgraph and I already have everything written with python.

I have one more question, what if I want to print both loop and born amplitude, how can that be done for the same process.
----

My reply B:

----
Yes, and also in principle you can access individually all terms of the squared order amplitudes individually if you force the specification of the "squared" order at generation time, for instance:

```
generate u u~ > d d~ [virt=QCD] QED^2<=99 QCD^2<=99; output TMP_TESTSQO; launch -f;
[...]
|================================================================================================
|| Results for process uux > ddx
|================================================================================================
|| Phase-Space point specification (E,px,py,pz)
|
| 5.0000000000000000e+02 0.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e+02
| 5.0000000000000000e+02 0.0000000000000000e+00 0.0000000000000000e+00 -5.0000000000000000e+02
| 4.9999999999999977e+02 1.1092428444383280e+02 4.4483078948812141e+02 -1.9955292993087880e+02
| 5.0000000000000000e+02 -1.1092428444383280e+02 -4.4483078948812141e+02 1.9955292993087869e+02
|
| Unknown numerical stability because MadLoop is in the initialization stage.
|
|| Total(*) Born contribution (GeV^0):
| Born = 5.4178705933854099e-01
|| Total(*) virtual contribution normalized with born*alpha_S/(2*pi):
| Finite = -4.2090576326108788e+01
| Single pole = 1.4228818635682719e+01
| Double pole = -5.3333333333333286e+00
| (*) The results above sum all starred contributions below
|
|| Born contribution of split orders *(QCD=4 QED=0) = 5.6645006116010321e-01
|| Born contribution of split orders *(QCD=2 QED=2) = -3.5955416370263185e-02
|| Born contribution of split orders *(QCD=0 QED=4) = 1.1292414548701049e-02
|
|| Virtual contribution of split orders *(QCD=6 QED=0):
| Accuracy = -1.0e+00
| Finite = -4.5041894645249958e-01
| Single pole = 1.5184917947040472e-01
| Double pole = -5.6736493948286615e-02
|| Virtual contribution of split orders *(QCD=4 QED=2):
| Accuracy = -1.0e+00
| Finite = 2.9459712231663993e-02
| Single pole = -1.0464002002650335e-02
| Double pole = 3.6013488269762573e-03
|| Virtual contribution of split orders *(QCD=2 QED=4):
| Accuracy = -1.0e+00
| Finite = -7.3087792354070320e-03
| Single pole = 3.3918349380617357e-03
| Double pole = -1.1310653023706438e-03
|================================================================================================
```

Now in the python bindings, the function `matrix2py.ml5_0_get_me` is coded so as to only return the final part of the loop.
But this is just because of the python wrapper (i.e. for instance the fortran driver returns everything, born and poles).

So if you want to access it from within Python I suggest you modify directly the binding. It is pretty straight forward to do, simply follow
the definition of the subroutine `GET_ME` in the file `f2py_wrapper.f` and you will see in it the following:

```
      ANS = MATELEM(1,0)
```
But you can decide to return other (or all) entries of this `MATELEM(i,j)` (short for Matrix Element) rank-2 array

i==0 : Born
i==1 : Finite part
i==2 : Single pole
i==3 : Double pole

j=0 : All contributions summed
j>1 : Contribution to the j^th combination of coupling orders (QED^2==X, QCD^2==Y, etc...)

You can find the bi-drectional maps between `j` and (X, Y, ....) using the fortran functions:
`FUNCTION ML5_0_ML5SOINDEX_FOR_SQUARED_ORDERS` giving j for specified (X, Y, ...)
and
`SUBROUTINE ML5_0_ML5GET_SQUARED_ORDERS_FOR_SOINDEX`
which can also be wrapped into python bindings if necessary (the former must be wrapped within a subroutine first too).

Anyway, I hope this helps and that you manage to access whatever you need from MadLoop from within Python directly.
----

Can you help with this problem?

Provide an answer of your own, or ask Mohammad for more information if necessary.

To post a message you must log in.