Skip to content

Commit

Permalink
Merge branch 'master' into model_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
APJansen committed Jul 13, 2023
2 parents 27f9357 + 4395179 commit 694417d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 51 deletions.
9 changes: 0 additions & 9 deletions doc/sphinx/source/tutorials/run-fit.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,6 @@ following the points presented above you can proceed with a fit.
downloaded automatically. Alternatively they can be obtained with the
``vp-get`` tool.

```eval_rst
.. note::
This step is not strictly necessary when producing a standard fit with
``n3fit`` but it is required by :ref:`validphys <vp-index>`
and it should therefore always be done. Note that :ref:`vp-upload <upload-fit>`
will fail unless this step has been followed. If necessary, this step can
be done after the fit has been run.
```
2. The ``n3fit`` program takes a ``runcard.yml`` as input and a replica number, e.g.
```n3fit runcard.yml replica``` where ``replica`` goes from 1-n where n is the
maximum number of desired replicas. Note that if you desire, for example, a 100
Expand Down
57 changes: 26 additions & 31 deletions n3fit/src/n3fit/layers/rotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,44 +56,39 @@ def __init__(
super().__init__(rotation_matrix, axes=1, **kwargs)


class FkRotation(MetaLayer):
class FkRotation(Rotation):
"""
Applies a transformation from the dimension-8 evolution basis
Applies a transformation from the dimension-9 evolution basis
to the dimension-14 evolution basis used by the fktables.
The input to this layer is a `pdf_raw` variable which is expected to have
a shape (1, None, 8), and it is then rotated to an output (1, None, 14)
a shape (1, None, 9), and it is then rotated to an output (1, None, 14)
"""

# TODO: Generate a rotation matrix in the input and just do tf.tensordot in call
# the matrix should be: (8, 14) so that we can just do tf.tensordot(pdf, rotmat, axes=1)
# i.e., create the matrix and inherit from the Rotation layer above
def __init__(self, output_dim=14, name="evolution", **kwargs):
self.output_dim = output_dim
super().__init__(name=name, **kwargs)

def call(self, pdf_raw):
# Transpose the PDF so that the flavour index is the first one
x = op.transpose(pdf_raw)
pdf_raw_list = [
0 * x[0], # photon
x[0], # sigma
x[1], # g
x[2], # v
x[3], # v3
x[4], # v8
x[8], # v15
x[2], # v24
x[2], # v35
x[5], # t3
x[6], # t8
x[0] - 4 * x[7], # t15 (c-)
x[0], # t24
x[0], # t35
]
ret = op.concatenate(pdf_raw_list)
# Concatenating destroys the batch index so we have to regenerate it
return op.batchit(ret)
rotation_matrix = self._create_rotation_matrix()
super().__init__(rotation_matrix, axes=1, name=name, **kwargs)

def _create_rotation_matrix(self):
"""Create the rotation matrix"""
array = np.array([
[0, 0, 0, 0, 0, 0, 0, 0, 0], # photon
[1, 0, 0, 0, 0, 0, 0, 0, 0], # sigma
[0, 1, 0, 0, 0, 0, 0, 0, 0], # g
[0, 0, 1, 0, 0, 0, 0, 0, 0], # v
[0, 0, 0, 1, 0, 0, 0, 0, 0], # v3
[0, 0, 0, 0, 1, 0, 0, 0, 0], # v8
[0, 0, 0, 0, 0, 0, 0, 0, 1], # v15
[0, 0, 1, 0, 0, 0, 0, 0, 0], # v24
[0, 0, 1, 0, 0, 0, 0, 0, 0], # v35
[0, 0, 0, 0, 0, 1, 0, 0, 0], # t3
[0, 0, 0, 0, 0, 0, 1, 0, 0], # t8
[1, 0, 0, 0, 0, 0, 0,-4, 0], # t15 (c-)
[1, 0, 0, 0, 0, 0, 0, 0, 0], # t24
[1, 0, 0, 0, 0, 0, 0, 0, 0], # t35
])
tensor = op.numpy_to_tensor(array.T)
return tensor


class AddPhoton(MetaLayer):
Expand Down
2 changes: 1 addition & 1 deletion validphys2/src/validphys/pdfplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ def plot_lumi1d(
ax.set_title(
f"${LUMI_CHANNELS[lumi_channel]}$ luminosity\n"
f"$\\sqrt{{s}}={format_number(sqrts/1000)}$ TeV "
f"$\\|y|<{format_number(y_cut)}$"
f"$\\|y\\|<{format_number(y_cut)}$"
)

return fig
Expand Down
7 changes: 3 additions & 4 deletions validphys2/src/validphys/photon/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ def __init__(self, theoryid, lux_params, replicas):
self.additional_errors = lux_params["additional_errors"]
self.luxseed = lux_params["luxseed"]

# TODO : maybe find a different name for fiatlux_dis_F2
path_to_F2 = theoryid.path / "fastkernel/fiatlux_dis_F2.pineappl.lz4"
path_to_FL = theoryid.path / "fastkernel/fiatlux_dis_FL.pineappl.lz4"
path_to_F2 = theoryid.path / "fastkernel/FIATLUX_DIS_F2.pineappl.lz4"
path_to_FL = theoryid.path / "fastkernel/FIATLUX_DIS_FL.pineappl.lz4"
self.path_to_eko_photon = theoryid.path / "eko_photon.tar"
with EKO.read(self.path_to_eko_photon) as eko:
self.q_in = np.sqrt(eko.mu20)
Expand All @@ -97,7 +96,7 @@ def __init__(self, theoryid, lux_params, replicas):
fl = sf.InterpStructureFunction(path_to_FL, self.luxpdfset.members[replica])
if not np.isclose(f2.q2_max, fl.q2_max):
log.error(
"FKtables for fiatlux_dis_F2 and fiatlux_dis_FL have two different q2_max"
"FKtables for FIATLUX_DIS_F2 and FIATLUX_DIS_FL have two different q2_max"
)

fiatlux_runcard["q2_max"] = float(f2.q2_max)
Expand Down
4 changes: 2 additions & 2 deletions validphys2/src/validphys/tests/photon/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def test_photon():
photon = Photon(test_theory, fiatlux_runcard, [replica])

# set up fiatlux
path_to_F2 = test_theory.path / "fastkernel/fiatlux_dis_F2.pineappl.lz4"
path_to_FL = test_theory.path / "fastkernel/fiatlux_dis_FL.pineappl.lz4"
path_to_F2 = test_theory.path / "fastkernel/FIATLUX_DIS_F2.pineappl.lz4"
path_to_FL = test_theory.path / "fastkernel/FIATLUX_DIS_FL.pineappl.lz4"
pdfs = fiatlux_runcard["luxset"].load()
f2 = sf.InterpStructureFunction(path_to_F2, pdfs.members[replica])
fl = sf.InterpStructureFunction(path_to_FL, pdfs.members[replica])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def test_zero_pdfs():
pdfs = ZeroPdfs()
test_theory = API.theoryid(theoryid=THEORY_QED)
theory = test_theory.get_description()
path_to_F2 = test_theory.path / "fastkernel/fiatlux_dis_F2.pineappl.lz4"
path_to_FL = test_theory.path / "fastkernel/fiatlux_dis_FL.pineappl.lz4"
path_to_F2 = test_theory.path / "fastkernel/FIATLUX_DIS_F2.pineappl.lz4"
path_to_FL = test_theory.path / "fastkernel/FIATLUX_DIS_FL.pineappl.lz4"

f2 = sf.InterpStructureFunction(path_to_F2, pdfs)
fl = sf.InterpStructureFunction(path_to_FL, pdfs)
Expand Down Expand Up @@ -78,7 +78,7 @@ def test_params():
test_theory = API.theoryid(theoryid=THEORY_QED)
theory = test_theory.get_description()
for channel in ["F2", "FL"]:
tmp = "fastkernel/fiatlux_dis_" + channel + ".pineappl.lz4"
tmp = "fastkernel/FIATLUX_DIS_" + channel + ".pineappl.lz4"
path_to_fktable = test_theory.path / tmp
struct_func = sf.InterpStructureFunction(path_to_fktable, pdfs.members[replica])
np.testing.assert_allclose(struct_func.q2_max, 1e8)
Expand All @@ -94,7 +94,7 @@ def test_interpolation_grid():
test_theory = API.theoryid(theoryid=THEORY_QED)
for replica in [1, 2, 3]:
for channel in ["F2", "FL"]:
tmp = "fastkernel/fiatlux_dis_" + channel + ".pineappl.lz4"
tmp = "fastkernel/FIATLUX_DIS_" + channel + ".pineappl.lz4"
path_to_fktable = test_theory.path / tmp
fktable = pineappl.fk_table.FkTable.read(path_to_fktable)
x = np.unique(fktable.bin_left(1))
Expand Down

0 comments on commit 694417d

Please sign in to comment.