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

Mix bands and replicas #1607

Merged
merged 11 commits into from
Mar 23, 2023
Merged

Mix bands and replicas #1607

merged 11 commits into from
Mar 23, 2023

Conversation

scarlehoff
Copy link
Member

Uses #1605 and #1606

Since the hopscotch replicas are single PDFs but we want to compare them to the "true" NNPDF we need to somehow be able to see in a single plot the hopscotch PDFs and the NNPDF bands. This is what I've come up with:

You might notice there is no label for the replicas, cannot see how to make them cross-talk (the bands and the replicas) but I don't think we will want to have this in the core code anyway? Or do we?

I've also removed the "central replica" since it makes no sense for the hopscotchy ones https://vp.nnpdf.science/avVrWwjGTsOtYFh1n5j66A==/

@scarlehoff scarlehoff changed the base branch from master to kinetic_energy_of_the_pdf September 29, 2022 13:07
Copy link
Member

@RoyStegeman RoyStegeman left a comment

Choose a reason for hiding this comment

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

On Friday people commented on the +1 appearing in the charm plot

validphys2/src/validphys/pdfplots.py Outdated Show resolved Hide resolved
@Zaharid
Copy link
Contributor

Zaharid commented Oct 3, 2022

Might make sense to make this an extra module if it is to be used (but let's see I'd say).

Base automatically changed from kinetic_energy_of_the_pdf to use_a_loggrid_for_arclength October 18, 2022 12:52
Base automatically changed from use_a_loggrid_for_arclength to master October 19, 2022 08:46
@RoyStegeman RoyStegeman marked this pull request as ready for review November 16, 2022 15:30
@RoyStegeman
Copy link
Member

So we want to add a boolean flag indicating whether or not to plot a PDF as a band. i.e. so we can do something like this:

pdfs:
  - {id: "NNPDF40_nnlo_as_01180_1000", label: "4.0 NNLO (1000 replicas)", plot_bands: False}

@scarlehoff
Copy link
Member Author

I think what @Zaharid had in mind is plot_band: [1, 4] and that will be read by action plot_pdf_mixed

@RoyStegeman
Copy link
Member

Right, also fine for me

@RoyStegeman
Copy link
Member

We should also think of what to do about replica0

@RoyStegeman
Copy link
Member

Please have a look if this is acceptable to you.

@RoyStegeman RoyStegeman changed the title [WIP] Mix bands and replicas Mix bands and replicas Jan 3, 2023

flstate.handles=[]
flstate.labels=[]
flstate.hatchit=plotutils.hatch_iter()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we moving these things, which were specific to the bands pdfs here?

Copy link
Member

@RoyStegeman RoyStegeman Jan 3, 2023

Choose a reason for hiding this comment

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

Because MixMatchPDFPlotter inherits from both ReplicaPDFPlotter and BandPDFPlotter, so the way ReplicaPDFPlotter deals with labels and handles has also been changed to be the same as BandPDFPlotter.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather not go that route: For one we don't want the legend for the replicas to be ComposedHandler. I think that all should look much more like what we do for pdfs_noband, i.e.

labels.append(pdf.label)
and not touch much the base class.

Copy link
Member

Choose a reason for hiding this comment

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

But this still uses the flstate handles and labels from BandPDFPlotter. The issue here is that ReplicaPDFPlotter has different instances for the handles and labels.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would most things work by inheriting from BandPDFPlotter first?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, all BandPDFPlotter and ReplicaPDFPlotter do is add a function on PDFPlotter to draw the figures and add the labels, where for ReplicaPDFPlotter the default matplotlib legend is used.

What I did so far is move the label generation from BandPDFPlotter to PDFPlotter and add the labels to flstate also for ReplicaPDFPlotter. Instead of moving the label generation to PDFPlotter it is indeed also possible to make ReplicaPDFPlotter inherit from BandPDFPlotter but in my mind that organisation makes less sense.

Copy link
Member

Choose a reason for hiding this comment

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

@Zaharid what would be your preferred solution? Feel free to change this PR yourself if that's easier than explaining.

@Zaharid
Copy link
Contributor

Zaharid commented Jan 3, 2023

I wonder if we should expand plot_pdfs do the same thing as plot_pdfs_mixed and remove the later?

@RoyStegeman
Copy link
Member

I wonder if we should expand plot_pdfs do the same thing as plot_pdfs_mixed and remove the later?

It does the same if you don't specify pdfs_plot_replicas. I was thinking about this as well, though since we would still have the plot_pdfreplicas (which we can't get rid off since the mixed_ variant doesn't print replica0) I don't mind also keeping plot_pdfs for symmetry.

Copy link
Member Author

@scarlehoff scarlehoff left a comment

Choose a reason for hiding this comment

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

To me it looks ok (just realized I cannot approve the PR because I am technically the author). I think for the scope of what we want this PR this is good. The changes it introduces are minimal and the new features are contained in their own functions/checks.

Could you check that doing a report with replicas doesn't change anything? (in principle it shouldn't but having an explicit example linked in the PR could be useful for future reference).

validphys2/src/validphys/checks.py Outdated Show resolved Hide resolved
validphys2/src/validphys/pdfplots.py Outdated Show resolved Hide resolved
validphys2/src/validphys/checks.py Outdated Show resolved Hide resolved
validphys2/src/validphys/pdfplots.py Outdated Show resolved Hide resolved
@RoyStegeman
Copy link
Member

Just to be sure, do I remember correctly that this is waiting for @Zaharid to implement some changes?

@RoyStegeman
Copy link
Member

@Zaharid do you have any idea when you'll look a this?

@scarlehoff
Copy link
Member Author

Should we merge this? i.e, is this "merge-ready" from your point of view @RoyStegeman ?

Comment on lines 200 to 205
color=color, zorder=1)
ax.plot(grid.xgrid, stats.central_value(), color=color,
linewidth=2,
label=pdf.label)
cv_line = ax.plot(grid.xgrid[0:1], stats.central_value()[0:1],
color=color, linewidth=2)
handle = cv_line[0]
labels.append(pdf.label)
handles.append(handle)
Copy link
Contributor

Choose a reason for hiding this comment

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

@scarlehoff @RoyStegeman This PR is adding a plot that is used in very limited circumstances, but that makes implementing new subclasses measurably more difficult as demostrated in this bit. I am not too happy with that as per the existing discussion. I see no pressure to merge it.

Copy link
Member Author

Choose a reason for hiding this comment

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

that makes implementing new subclasses measurably more difficult as demostrated in this bit

How does this bit demonstrate that?

Copy link
Member Author

Choose a reason for hiding this comment

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

(also, the very limited circumstances are already in the arxiv, which is more than one can say of many of the other plots that we have)

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of specifying label in the plot call and letting mpl handle the construction of the legend automatically, one has to pass in manually the components that make it, and override the behaviour of ComposedHandler, which is there for some reason despite being specific to the band plots.

This complexity makes sense where it was, in the band plots, because we want a complicated legend handler in there, but not in all present and future sublcasses.

Copy link
Member Author

Choose a reason for hiding this comment

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

The only other option that I see is to copy the whole of the draw method of ReplicaPDFPlotter into MixMatchPDFPlotter instead of reusing ReplicaPDFPlotter.

RoyStegeman added a commit that referenced this pull request Mar 23, 2023
@RoyStegeman
Copy link
Member

Ok I think now it should be ok for @Zaharid ?

RoyStegeman and others added 8 commits March 23, 2023 10:30
Adds plot_pdfs_mixed_kinetic_energy and plot_pdfs_mixed for the mixed plotting of uncertainty bands and replicas in the same figure.
Co-authored-by: Juan M. Cruz-Martinez <juacrumar@lairen.eu>
Copy link
Contributor

@Zaharid Zaharid left a comment

Choose a reason for hiding this comment

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

Looks good indeed. Everything works and the error messages are of the expected high quality

 $ validphys mixbandreplicas.yaml                             (nnpdfdev) 
[WARNING]: Output folder exists: /home/zah/nngit/nnpdf/validphys2/examples/output Overwriting contents
[ERROR]: Cannot process a resource:
Could not process the resource 'plot_pdfs_mixed', required by:
 - template_text
 - report
pdfs_plot_replicas should be a list of PDF IDs (strings) or a list of PDF indexes (integers, starting from one)

However I think we need to change the name of the parameter. Calling it pdfs_plot_replicas when we have plot_pdfreplicas to plot replicas is just too confusing.

I am happy to change the name myself if someone suggests a good one.

@RoyStegeman
Copy link
Member

RoyStegeman commented Mar 23, 2023

Good point. How about something along the lines of mixmatch_as_replicas? Since the class is called MixMatchPDFPlotter (actually, I'm not so sure what the "match" is doing in that name).

@scarlehoff
Copy link
Member Author

Probably it makes sense to change to MixBandPDFPlotter

@RoyStegeman
Copy link
Member

Feel free to update it again if you have a better idea @Zaharid.

@RoyStegeman RoyStegeman added the enhancement New feature or request label Mar 23, 2023
Copy link
Contributor

@Zaharid Zaharid left a comment

Choose a reason for hiding this comment

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

I don't love that name either but can't really think of much.

@RoyStegeman RoyStegeman merged commit a91f38e into master Mar 23, 2023
@RoyStegeman RoyStegeman deleted the mix_match_band_replicas branch March 23, 2023 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants