-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description <!-- Provide a brief description of the PR's purpose here. --> This PR introduces a visualization function that plots CVTArchive in 3D. There are a couple of variations, including: **Solid cells:** ![3d](https://github.com/icaros-usc/pyribs/assets/38124174/0f6e4247-b054-49c0-b90f-79c7365ca9a7) **Translucent cells:** ![cell_alpha](https://github.com/icaros-usc/pyribs/assets/38124174/957ede30-8269-410a-adac-e4aa1c463fab) **Wireframe (transparent cells):** ![transparent](https://github.com/icaros-usc/pyribs/assets/38124174/1ec70793-1d93-456b-8726-2865f551c464) **Wireframe with scatterplot:** ![plot_elites](https://github.com/icaros-usc/pyribs/assets/38124174/a101cefd-7387-4114-83c9-26efba29fd34) ## TODO <!-- Notable points that this PR has either accomplished or will accomplish. --> - [x] Prototype different plots - [x] Decide on API for activating different variations - [x] Tests - [x] Documentation examples ## Questions <!-- Any concerns or points of confusion? --> ## Status - [x] I have read the guidelines in [CONTRIBUTING.md](https://github.com/icaros-usc/pyribs/blob/master/CONTRIBUTING.md) - [x] I have formatted my code using `yapf` - [x] I have tested my code by running `pytest` - [x] I have linted my code with `pylint` - [x] I have added a one-line description of my change to the changelog in `HISTORY.md` - [x] This PR is ready to go
- Loading branch information
Showing
19 changed files
with
606 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+107 KB
tests/visualize/baseline_images/cvt_archive_3d_plot_test/3d_rect_reorder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+284 KB
tests/visualize/baseline_images/cvt_archive_3d_plot_test/cell_alpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+108 KB
tests/visualize/baseline_images/cvt_archive_3d_plot_test/coolwarm_cmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+89.1 KB
tests/visualize/baseline_images/cvt_archive_3d_plot_test/listed_cmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+287 KB
tests/visualize/baseline_images/cvt_archive_3d_plot_test/plot_centroids.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+307 KB
tests/visualize/baseline_images/cvt_archive_3d_plot_test/plot_elites.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+320 KB
tests/visualize/baseline_images/cvt_archive_3d_plot_test/plot_samples.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+276 KB
tests/visualize/baseline_images/cvt_archive_3d_plot_test/transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+93.9 KB
tests/visualize/baseline_images/cvt_archive_3d_plot_test/vmin_equals_vmax.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+123 KB
tests/visualize/baseline_images/cvt_archive_3d_plot_test/voronoi_style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
"""Tests for cvt_archive_3d_plot. | ||
See README.md for instructions on writing tests. | ||
""" | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import pytest | ||
from matplotlib.testing.decorators import image_comparison | ||
|
||
from ribs.archives import CVTArchive | ||
from ribs.visualize import cvt_archive_3d_plot | ||
|
||
from .conftest import add_uniform_sphere_3d | ||
|
||
# pylint: disable = redefined-outer-name | ||
|
||
# Tolerance for root mean square difference between the pixels of the images, | ||
# where 255 is the max value. We have a pretty high tolerance for | ||
# `cvt_archive_3d_plot` since 3D rendering tends to vary a bit. | ||
CVT_IMAGE_TOLERANCE = 1.0 | ||
|
||
# | ||
# Fixtures | ||
# | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def cvt_archive_3d(): | ||
"""Deterministically-created CVTArchive.""" | ||
ranges = np.array([(-1, 1), (-1, 1), (-1, 1)]) | ||
archive = CVTArchive( | ||
solution_dim=3, | ||
cells=500, | ||
ranges=ranges, | ||
samples=10_000, | ||
seed=42, | ||
) | ||
add_uniform_sphere_3d(archive, *ranges) | ||
return archive | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def cvt_archive_3d_rect(): | ||
"""Same as above, but the dimensions have different ranges.""" | ||
ranges = [(-1, 1), (-2, 0), (1, 3)] | ||
archive = CVTArchive( | ||
solution_dim=3, | ||
cells=500, | ||
ranges=ranges, | ||
samples=10_000, | ||
seed=42, | ||
) | ||
add_uniform_sphere_3d(archive, *ranges) | ||
return archive | ||
|
||
|
||
# | ||
# Argument validation tests | ||
# | ||
|
||
|
||
def test_no_samples_error(): | ||
# This archive has no samples since custom centroids were passed in. | ||
archive = CVTArchive(solution_dim=2, | ||
cells=2, | ||
ranges=[(-1, 1), (-1, 1)], | ||
custom_centroids=[[0, 0], [1, 1]]) | ||
|
||
# Thus, plotting samples on this archive should fail. | ||
with pytest.raises(ValueError): | ||
cvt_archive_3d_plot(archive, plot_samples=True) | ||
|
||
|
||
# | ||
# Tests on archive with (-1, 1) range. | ||
# | ||
|
||
|
||
@image_comparison(baseline_images=["3d"], | ||
remove_text=False, | ||
extensions=["png"], | ||
tol=CVT_IMAGE_TOLERANCE) | ||
def test_3d(cvt_archive_3d): | ||
plt.figure(figsize=(8, 6)) | ||
cvt_archive_3d_plot(cvt_archive_3d) | ||
|
||
|
||
@image_comparison(baseline_images=["3d"], | ||
remove_text=False, | ||
extensions=["png"], | ||
tol=CVT_IMAGE_TOLERANCE) | ||
def test_3d_custom_axis(cvt_archive_3d): | ||
ax = plt.axes(projection="3d") | ||
cvt_archive_3d_plot(cvt_archive_3d, ax=ax) | ||
|
||
|
||
@image_comparison(baseline_images=["3d_rect"], | ||
remove_text=False, | ||
extensions=["png"], | ||
tol=CVT_IMAGE_TOLERANCE) | ||
def test_3d_rect(cvt_archive_3d_rect): | ||
plt.figure(figsize=(8, 6)) | ||
cvt_archive_3d_plot(cvt_archive_3d_rect) | ||
|
||
|
||
@image_comparison(baseline_images=["3d_rect_reorder"], | ||
remove_text=False, | ||
extensions=["png"], | ||
tol=CVT_IMAGE_TOLERANCE) | ||
def test_3d_rect_reorder(cvt_archive_3d_rect): | ||
plt.figure(figsize=(8, 6)) | ||
cvt_archive_3d_plot(cvt_archive_3d_rect, measure_order=[1, 2, 0]) | ||
|
||
|
||
@image_comparison(baseline_images=["limits"], | ||
remove_text=False, | ||
extensions=["png"], | ||
tol=CVT_IMAGE_TOLERANCE) | ||
def test_limits(cvt_archive_3d): | ||
plt.figure(figsize=(8, 6)) | ||
cvt_archive_3d_plot(cvt_archive_3d, vmin=-1.0, vmax=-0.5) | ||
|
||
|
||
@image_comparison(baseline_images=["listed_cmap"], | ||
remove_text=False, | ||
extensions=["png"], | ||
tol=CVT_IMAGE_TOLERANCE) | ||
def test_listed_cmap(cvt_archive_3d): | ||
plt.figure(figsize=(8, 6)) | ||
cvt_archive_3d_plot(cvt_archive_3d, cmap=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]) | ||
|
||
|
||
@image_comparison(baseline_images=["coolwarm_cmap"], | ||
remove_text=False, | ||
extensions=["png"], | ||
tol=CVT_IMAGE_TOLERANCE) | ||
def test_coolwarm_cmap(cvt_archive_3d): | ||
plt.figure(figsize=(8, 6)) | ||
cvt_archive_3d_plot(cvt_archive_3d, cmap="coolwarm") | ||
|
||
|
||
@image_comparison(baseline_images=["vmin_equals_vmax"], | ||
remove_text=False, | ||
extensions=["png"], | ||
tol=CVT_IMAGE_TOLERANCE) | ||
def test_vmin_equals_vmax(cvt_archive_3d): | ||
plt.figure(figsize=(8, 6)) | ||
cvt_archive_3d_plot(cvt_archive_3d, vmin=-0.95, vmax=-0.95) | ||
|
||
|
||
@image_comparison(baseline_images=["plot_centroids"], | ||
remove_text=False, | ||
extensions=["png"], | ||
tol=CVT_IMAGE_TOLERANCE) | ||
def test_plot_centroids(cvt_archive_3d): | ||
plt.figure(figsize=(8, 6)) | ||
cvt_archive_3d_plot(cvt_archive_3d, plot_centroids=True, cell_alpha=0.1) | ||
|
||
|
||
@image_comparison(baseline_images=["plot_samples"], | ||
remove_text=False, | ||
extensions=["png"], | ||
tol=CVT_IMAGE_TOLERANCE) | ||
def test_plot_samples(cvt_archive_3d): | ||
plt.figure(figsize=(8, 6)) | ||
cvt_archive_3d_plot(cvt_archive_3d, plot_samples=True, cell_alpha=0.1) | ||
|
||
|
||
@image_comparison(baseline_images=["voronoi_style"], | ||
remove_text=False, | ||
extensions=["png"], | ||
tol=CVT_IMAGE_TOLERANCE) | ||
def test_voronoi_style(cvt_archive_3d): | ||
plt.figure(figsize=(8, 6)) | ||
cvt_archive_3d_plot(cvt_archive_3d, lw=3.0, ec="grey") | ||
|
||
|
||
@image_comparison(baseline_images=["cell_alpha"], | ||
remove_text=False, | ||
extensions=["png"], | ||
tol=CVT_IMAGE_TOLERANCE) | ||
def test_cell_alpha(cvt_archive_3d): | ||
plt.figure(figsize=(8, 6)) | ||
cvt_archive_3d_plot(cvt_archive_3d, cell_alpha=0.1) | ||
|
||
|
||
@image_comparison(baseline_images=["transparent"], | ||
remove_text=False, | ||
extensions=["png"], | ||
tol=CVT_IMAGE_TOLERANCE) | ||
def test_transparent(cvt_archive_3d): | ||
plt.figure(figsize=(8, 6)) | ||
cvt_archive_3d_plot(cvt_archive_3d, cell_alpha=0.0) | ||
|
||
|
||
@image_comparison(baseline_images=["plot_elites"], | ||
remove_text=False, | ||
extensions=["png"], | ||
tol=CVT_IMAGE_TOLERANCE) | ||
def test_plot_elites(cvt_archive_3d): | ||
plt.figure(figsize=(8, 6)) | ||
cvt_archive_3d_plot(cvt_archive_3d, cell_alpha=0.0, plot_elites=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters