diff --git a/paddle_quantum/utils.py b/paddle_quantum/utils.py index 66a0651a768f9be559f07430a9b83f402742e756..5c2d68bf23e9a36eefb6c932ac9804aaf6330579 100644 --- a/paddle_quantum/utils.py +++ b/paddle_quantum/utils.py @@ -1758,8 +1758,8 @@ def plot_density_graph(density_matrix: Union[paddle.Tensor, np.ndarray], real = real.reshape(-1) imag = imag.reshape(-1) - ax_real.bar3d(xx, yy, np.zeros_like(real), size, size, real) - ax_imag.bar3d(xx, yy, np.zeros_like(imag), size, size, imag) + ax_real.bar3d(xx, yy, np.zeros_like(real), size, size, np.abs(real)) + ax_imag.bar3d(xx, yy, np.zeros_like(imag), size, size, np.abs(imag)) return figure diff --git a/test_and_documents/test.py b/test_and_documents/test.py index 9423751c9544c4367cc603824a3c0800d56f2528..249ba61c3ba7f6c8e3ab46d7c2e450e0b44d5b18 100644 --- a/test_and_documents/test.py +++ b/test_and_documents/test.py @@ -1,6 +1,7 @@ from paddle_quantum.circuit import UAnsatz -from paddle import kron -from paddle_quantum.state import vec,density_op +import matplotlib.pyplot as plt +from paddle_quantum.utils import plot_density_graph +import numpy as np import paddle import unittest @@ -35,7 +36,7 @@ def test_state_vector(): class TestPlotDensityGraph(unittest.TestCase): def setUp(self): self.func = plot_density_graph - self.x_np = np.random.rand(4, 4) + np.random.rand(4, 4) * 1j + self.x_np = (np.random.rand(8, 8) + np.random.rand(8, 8) * 1j)-0.5-0.5j self.x_tensor = paddle.to_tensor(self.x_np) def test_input_type(self):