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

unit test for plot2D based on image hashes #2389

Open
oskooi opened this issue Feb 2, 2023 · 3 comments
Open

unit test for plot2D based on image hashes #2389

oskooi opened this issue Feb 2, 2023 · 3 comments
Assignees
Labels

Comments

@oskooi
Copy link
Collaborator

oskooi commented Feb 2, 2023

plot2D seems to no longer work correctly for cylindrical coordinates. As an example, python/examples/zone_plate.py of Tutorial/Focusing Properties of a Binary-Phase Zone Plate produces the wrong output:

zone_plate_epsilon

This particular example was most recently corrected in #2136:

zone_plate_plot2D

From the images, the problem seems to be that the $R$ axis is not properly defined: it should be the interval (0,R) rather than (-R/2,+R/2).

@oskooi oskooi added the bug label Feb 2, 2023
@oskooi oskooi self-assigned this Feb 2, 2023
@oskooi
Copy link
Collaborator Author

oskooi commented Feb 4, 2023

As a second check, I rebuilt from the master branch (b86b476) and then reran the example above. The output is correct. Not sure why the output was incorrect previously. There is no bug in plot2D after all.

Anyhow, it would be useful to add a set of unit tests for plot2D. It seems there are unit tests for plot2D in test_visualization.py but they do not actually do anything:

def test_plot2D(self):
# Check plotting of geometry with several sources, monitors, and PMLs
f = plt.figure()
ax = f.gca()
sim = setup_sim()
ax = sim.plot2D(ax=ax)
if mp.am_master():
hash_figure(f)
# self.assertAlmostEqual(hash_figure(f),10231488)
# Check plotting of fields after timestepping
f = plt.figure()
ax = f.gca()
sim.run(until=200)
ax = sim.plot2D(ax=ax, fields=mp.Ez)
if mp.am_master():
hash_figure(f)
# self.assertAlmostEqual(hash_figure(f),79786722)
# Check output_plane feature
f = plt.figure()
ax = f.gca()
vol = mp.Volume(center=mp.Vector3(), size=mp.Vector3(2, 2))
ax = sim.plot2D(ax=ax, fields=mp.Ez, output_plane=vol)
if mp.am_master():
hash_figure(f)
# self.assertAlmostEqual(hash_figure(f),68926258)

Note that the assertAlmostEqual statements are all commented out.

@smartalecH, do we just need to update the hash values in this test in order to reenable it?

@smartalecH
Copy link
Collaborator

IIRC, the hash value checks were rather flaky. Essentially the same plots were producing different hashes depending on the CI build machine etc (back in the days of Travis).

We could once again look into how matplotlib does CI (which is how we originally came up with the hash comparisons). I'm sure some new techniques have emerged in the last five years. Maybe even some native to matplotlib itself.

@oskooi
Copy link
Collaborator Author

oskooi commented Feb 4, 2023

We could once again look into how matplotlib does CI (which is how we originally came up with the hash comparisons). I'm sure some new techniques have emerged in the last five years. Maybe even some native to matplotlib itself.

Seems there is indeed support within matplotlib for comparing images as part of a unit test:

https://matplotlib.org/stable/devel/testing.html#writing-an-image-comparison-test

@oskooi oskooi changed the title plot2D not working correctly for cylindrical coordinates unit test for plot2D based on image hashes Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants