Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix backward matching #247

Merged
merged 8 commits into from
Apr 21, 2023
Merged

Fix backward matching #247

merged 8 commits into from
Apr 21, 2023

Conversation

niclaurenti
Copy link
Contributor

Pull request made to fix the bug in the backward matching:
in the function build_ome the argument backward_method arrives as an object of the type InversionMethod.EXACT or InversionMethod.EXPANDED but we are checking it to be equal to strings. In conclusion the backward matching is never applied (the matching operator is always the upwards one) unless we add the .value.

@felixhekhorn felixhekhorn added the bug Something isn't working label Apr 20, 2023
@felixhekhorn
Copy link
Contributor

  • as conjectured: this most likely is another side effect of Use tempdir during execution #172 (since the thing was introduced there)
  • can you please fix the tests? (it seems they are not using what is used in practice)
  • I wonder whether to fix in the opposite way, i.e. fixing the RHS instead of LHS: if backward_method.value == InversionMethod.EXACT (constant literals should be available inside nuba, see
    if sv_mode == sv.Modes.exponentiated:
    )
  • minor comment (not to be fixed in this PR): we should kill strings from numba since they are slowing down
  • I immediately triggered the LHA benchmark https://github.com/NNPDF/eko/actions/runs/4755747561

@felixhekhorn
Copy link
Contributor

Also should we add a forward-backward run to the iso-bench? actually, can we bring

# def test_matching_grid(
# self,
# ):
# # test matching_ome_forward @ matching_ome_backward gives ID matrix or zeros
back to live?

@felixhekhorn
Copy link
Contributor

Also should we add a forward-backward run to the iso-bench? actually, can we bring

# def test_matching_grid(
# self,
# ):
# # test matching_ome_forward @ matching_ome_backward gives ID matrix or zeros

back to live?

maybe the problem was time ... @giacomomagni do you remember?

@alecandido
Copy link
Member

@felixhekhorn should we merge the quick fix, and worry about tests at a later stage?

@niclaurenti
Copy link
Contributor Author

@felixhekhorn should we merge the quick fix, and worry about tests at a later stage?

Before merging I would like to perform the benchmark of evolving to 1.65 and then back to 100 to see whether it is fixed or not

@giacomomagni
Copy link
Collaborator

Also should we add a forward-backward run to the iso-bench? actually, can we bring

# def test_matching_grid(
# self,
# ):
# # test matching_ome_forward @ matching_ome_backward gives ID matrix or zeros

back to live?

maybe the problem was time ... @giacomomagni do you remember?

If I recall correctly problems where both time but also accuracy, because you had to test against and identity matrix, which was not really good.

Copy link
Collaborator

@giacomomagni giacomomagni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments.
Could you please update also here:

backward_method : ["exact", "expanded" or ""]

backward_method : ["exact", "expanded" or ""]

and maybe we should use None instead of "" here and similar:

(backward_method != "" and ker_base.is_singlet)

Otherwise also adding .value in config would be more consistent with the other modules of Eko. Simply changing here:

config["backward_inversion"] = configs.inversion_method

@alecandido
Copy link
Member

Otherwise also adding .value in config would be more consistent with the other modules of Eko. Simply changing here:

config is part of the issue: if it hadn't passed through an opaque dictionary, we might have been warned of the type inconsistency by some static analyzer (I will soon add mypy explicitly, but PyRight in the editor should have already noticed...). I would keep propagating the more specific types, in order to avoid similar issues later on.

@niclaurenti
Copy link
Contributor Author

Hi @giacomomagni

and maybe we should use None instead of "" here and similar:

I agree with using None instead of ""

Otherwise also adding .value in config would be more consistent with the other modules of Eko. Simply changing here:

but I would pass the whole object to config and not just the string

@alecandido
Copy link
Member

alecandido commented Apr 21, 2023

Actually, thinking about the alternatives "" and None for backward_inversion, I believe we can avoid both: let's always have an inversion strategy, this will avoid us to always consider the case in which it is not there.

If we need a default we could pick one of the two (in case we really want a default, and we really want to avoid one of them, we can add a NULL variant to InversionMethod, but I'd prefer to avoid).

@felixhekhorn

@giacomomagni
Copy link
Collaborator

giacomomagni commented Apr 21, 2023

Actually, thinking about the alternatives "" and None for backward_inversion, I believe we can avoid both: let's always have an inversion strategy, this will avoid us to always consider the case in which it is not there.

I think the None option was done in order to avoid passing an additional variable is_backward to quad_ker or similar.
But for sure there are other options.

@felixhekhorn
Copy link
Contributor

Actually, thinking about the alternatives "" and None for backward_inversion, I believe we can avoid both: let's always have an inversion strategy, this will avoid us to always consider the case in which it is not there.

If we need a default we could pick one of the two (in case we really want a default, and we really want to avoid one of them, we can add a NULL variant to InversionMethod, but I'd prefer to avoid).

@felixhekhorn

as already said - most likely we can not stick to our no-default-strategy in the light of #145 ... so let's assume something

I think the None option was done in other to avoid passing an additional variable is_backward to quad_ker or similar. But for sure there are other options.

indeed, now as you say I remember:

if backward_method == "expanded":
# expended inverse
if matching_order[0] >= 1:
ome -= a_s * A[0]
if matching_order[0] >= 2:
ome += a_s**2 * (-A[1] + A[0] @ A[0])
if matching_order[0] >= 3:
ome += a_s**3 * (-A[2] + A[0] @ A[1] + A[1] @ A[0] - A[0] @ A[0] @ A[0])
else:
# forward or exact inverse
if matching_order[0] >= 1:
ome += a_s * A[0]
if matching_order[0] >= 2:
ome += a_s**2 * A[1]
if matching_order[0] >= 3:
ome += a_s**3 * A[2]
# need inverse exact ? so add the missing pieces
if backward_method == "exact":
ome = np.linalg.inv(ome)

@alecandido
Copy link
Member

alecandido commented Apr 21, 2023

I think the None option was done in other to avoid passing an additional variable is_backward to quad_ker or similar. But for sure there are other options.

indeed, now as you say I remember:

But then we are already passing to Numba something that is either expanded or "everything else".
Maybe we can simplify even backward_method by using a boolean backward_expanded: we save a string and string comparison, with something that is fully equivalent (we'd be throwing away the option of having other backward methods, but it doesn't seem to me that relevant).

I take it back, backward_method == "exact" is used down below, at most we could use integers: let's keep string comparison, for the time being.

But we can still use the two methods, and just keep the empty string at the level of Numba (Numba usage is internal, we do not need to propagate to everywhere else, and outside it, we know if it is backward or not).

@niclaurenti
Copy link
Contributor Author

niclaurenti commented Apr 21, 2023

@alecandido @felixhekhorn So in the end what we decided? I revert the changes to use again strings?

@alecandido
Copy link
Member

@alecandido @felixhekhorn So in the end what we decided? I revert the changes to use again strings?

Nono, I was talking about strings inside Numba (where for sure we can not propagate Python's enum, unless we convert to integers).

About your changes, keep them as they are. I would not really consider the option of using strings again.

@niclaurenti niclaurenti marked this pull request as ready for review April 21, 2023 09:43
@niclaurenti niclaurenti merged commit 86fe3c5 into master Apr 21, 2023
@niclaurenti niclaurenti deleted the fix-back_match branch April 21, 2023 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants