-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
ENH: Detaching plotly from the processing and allowing other drawers. #312
Conversation
Looks amazing! Thanks! Yes, more work!! ;) And great you only started with one. Then we can have an iteration there! |
I was thinking about that but since you can write as many different drawers as you want that use the same plotting framework for a given plot, So
What do you have in mind? 🤔 |
True, but you would still have to name the
For exactly the general picture you mention, there is no need to make users think this is restricted to drawing stuff. I kind of like the generality here. It is what matplotlib uses as words for different frameworks. So it is also a matter of choosing a common word. So I have to say, backend would be the proper word :) |
Hey Nick, do you think we can work on this before the SIESTA school? I would like to present it there 😅 |
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.
Yes, i think we should finish this.
However, we still have to decide on "backend" name. I would still like the name to be backend.
sisl/viz/_plotly_plotables.py
Outdated
# register(GeomSile, GeometryPlot, 'geom_file', default=True) | ||
# register(GeomSile, BondLengthMap, 'geom_file') | ||
|
||
for HSile in get_siles(attrs=["read_hamiltonian"]): |
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.
if you don't use __all__
then you should prefix local variables with _
to make them private.
Could you also rebase? |
Great, thank youuuu! I will rename it to backend. |
Now the path to a given drawer is I understand that the first "drawers" could be replaced by Also how would you rename the classes? |
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'll probably have some more stuff. But this drawer
vs. backend
seems like the most pressing thing?
Ok, the renaming is done. The next things are:
|
I think we shouldn't load unless a user wants too do it, i.e. lazy load when doing
Definitely!!! :) |
I'm not saying to load them on |
I propose that at that point everything is loaded by default and if you want you can block the auto loading with env variables. But I think the average user would want everything to be loaded at that point without any extra configuration. |
This is fine for me. |
@pfebrer could you unmark "draft" |
By the way, in this PR or a subsequent one I would like to finally decide what the CLI for plotting should look like, now that everything will be unified. |
See here I think we should go for |
In a subsequent one! :) |
Ok, I added a Templates are registered on the backends manager with the Any suggestion/comments about the organization and implementation of this? |
@pfebrer I have just rebased, could you please hold your branch for now (locally). There were no conflicts, but I am trying to fix the warnings! |
When I run the tests I get lots of "print-out errors", but not formal errors?
is this on purpose, or should this test actually have failed? |
sisl/viz/plots/geometry.py
Outdated
otherwise they are taken from the geometry. | ||
axis: {0,1,2, "x", "y", "z", "a", "b", "c"} or array-like of shape 3, optional | ||
the direction to be displayed along the X axis. | ||
If it's an int, it will interpreted as the index of the cell axis. |
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.
In your _sanitize_axis
routine you interpret (0, 1, 2) as Cartesian coordinates?
I was confused whether cell
meant lattice or Cartesian cell?
Please clarify?
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.
This is an old docstring that should have been changed. Initially 0
meant the first lattice vector, but since I realised that it was strange that users needed to project along a lattice vector I decided to change it. Now, as you understood, 0
is the same as "x"
as it's always more comfortable to write integers than to write strings. Any opinion on whether this is fine or not (it may be inconsistent with other parts of sisl, for example)?
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.
My other implementation here sisl/utils/misc.py:direction
could solve this kind of easily. I would suspect integer indices to respect lattice vectors. Typing an x
vs. a 0
is not a problem I think
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.
Hmm ok, the problem is that it's not an x
, it's an "x"
:) And when you do it lots of times it becomes annoying to write the "
.
I would suspect integer indices to respect lattice vectors.
Yeah me too, that's why this was the initial idea. But for the representations I can't see many cases where you would want to project the lattice vectors into the plot axes to visualize real space data.
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 isn't this in the GUI drop-down? I think "x"
is fine to force people to do. It makes the code readable. Integers are not really good either. Better to force good habits than remove 2 characters. :)
Perhaps now there isn't much reason, but perhaps later...
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.
Hmm maybe the issues that I have could be solved by allowing multicharacter strings also? I mean axes="xyz"
would be the same as axes=["x", "y", "z"]
. I think my speed thrive would be satisfied with that :) hahahah
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.
So it should be easy to use, not to be fast.
I understand this, but if the point of the software is to allow quick visualization, then I think "quick to use" is also a feature that one would expect.
I really don't think users are in this category ;)
Only very high level users will be irritated about this.
I'm worried that people will just use
0,1,2
as shortcuts for"x", "y", "z"
when they have an (almost) orthogonal cell, not because they want the projection of the axes, but because they want the cartesian representation and it's more convenient to write integers. This will then not behave in the same way when the cell is not orthogonal.
That is fine, there has to be rules. And you and I both thought that the lattice vectors were natural for integer indices, and so a large fraction of users will probably also have that thought. Of course there will be users that think the other way around, but regardless you'll get some users who don't expect the outcome of the arguments.
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.
Does this solution make sense to you?
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.
Ok, I see that we commented the same at the same time, then great!
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.
yes, great. I think this is better. Also consistency in sisl and elsewhere is key, I use integers as lattice vector matches.
Ok, I have amended another commit. Please ensure that you re-fetch your branch (I have overwritten it). Sorry for doing it like this, but it cleared many warnings and added some things needed. |
This warning is to be expected. These tests are just to check that the basic functionality of the |
Yes, I think we should filter, I tried to manage this in some of my tests, and this is still a work-in-progress. But it makes it much easier to figure out if something goes wrong. In fact pytest can check where a specific warning has been raised, see here |
I am done pushing to your branch, so perhaps you could have a go, and the we can merge this? |
I removed all the warnings that are due to the failed initialization of the plot, now I only get some warnings for using
I have two questions:
gr = sisl.geom.graphene()
H = sisl.Hamiltonian(gr)
H.construct([(0.1, 1.44), (0, -2.7)])
H.plot.pdos(Erange=[-5,5])
|
Probably because the default level of the warnings module is too low.
One should pass a wrapper: |
It took me a while to make geometries and grids play well with each other in all cases. This is what I ended up doing for the different possible values of axes:
|
Sounds like a good compromise! |
Good, then I just have to finish some details and update the documentation. Then we can merge this :) |
I'd say it's finished now. There might still be some inconsistent things, but we can figure them out along the way, as we get some feedback :) |
Do you plan to release a version soon? I would like to parallelize the PDOS and (fat)bands calculations (I will do it today) and agree on a CLI before the next release 😄 |
No, we can wait for that. Definitely the cli would be great to have in the next release. |
Good! |
First of all, sorry to give you more work to review :)
Second: The idea is actually working and I'm excited to have this implemented!
PR introduction
Basically, as we were discussing in #266 (comment) and the following comments, this PR is a first sketch to have three different steps (not necessarily with these names):
The entry and draw phases would allow the user to register new methods.
Here is the diagram that I draw initially to explain the concept:
In this PR, the separation of the drawing parts from the rest is done so that we can have this distinction.
What has been done
sisl.viz
sisl.viz.drawers
where the different drawers are implemented. Right now you can find a folder forplotly
and another formatplotlib
.sisl/viz/drawers/plotly/drawer.py
that contains the generic things forplotly
figures. Same for matplotlib.sisl/viz/drawers/plotly/drawers/*
contains the specific drawers for each plot (right now only bands), which are then registered to the corresponding plotting class (in the same file). Same for matplotlib.Plot
is defined (i.e. inPlot.__init_subclass__
), it receives a drawers manager, which will be waiting for new drawers to be registered. This drawers manager is defined insisl.viz.drawers._plot_drawers
. I just did it as simple as I could, waiting for you to reimplement it as you find suitable.PlotEngine
insisl.viz._plotables
doesn't make sense anymore becausedrawer
is just a regular setting that you can update on the fly.The only specific plot to which the changes have been implemented for now is the bands plot. This is because I wanted to have a proof of concept so that you can give your opinion and propose different approaches. After we agree with what's the best approach, I can do it with the rest of plots. Presumably it is a significant amount of work so it's better to first have a consensus :)
How it works
The settings of
BandsPlot
of course work regardless of the drawer. If you want to render subplots, this is also drawer-aware:By the way: I have tried to uninstall plotly and the bands work with the
matplotlib
drawer :)Looking forward to your feedback!