-
Notifications
You must be signed in to change notification settings - Fork 6
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
Mix bands and replicas #1607
Conversation
There was a problem hiding this 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
Might make sense to make this an extra module if it is to be used (but let's see I'd say). |
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:
|
I think what @Zaharid had in mind is |
Right, also fine for me |
We should also think of what to do about replica0 |
Please have a look if this is acceptable to you. |
7e12196
to
19b95c2
Compare
validphys2/src/validphys/pdfplots.py
Outdated
|
||
flstate.handles=[] | ||
flstate.labels=[] | ||
flstate.hatchit=plotutils.hatch_iter() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
nnpdf/validphys2/src/validphys/pdfplots.py
Line 441 in b08ec66
labels.append(pdf.label) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this 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).
Just to be sure, do I remember correctly that this is waiting for @Zaharid to implement some changes? |
@Zaharid do you have any idea when you'll look a this? |
Should we merge this? i.e, is this "merge-ready" from your point of view @RoyStegeman ? |
validphys2/src/validphys/pdfplots.py
Outdated
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
This is the agreed upon solution #1607 (comment)
Ok I think now it should be ok for @Zaharid ? |
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>
This is the agreed upon solution #1607 (comment)
18980dd
to
855f3ff
Compare
There was a problem hiding this 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.
Good point. How about something along the lines of |
Probably it makes sense to change to MixBandPDFPlotter |
Feel free to update it again if you have a better idea @Zaharid. |
There was a problem hiding this 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.
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==/