From 16e7d3bf2dba7e94e6faf5c853faf0e913e1f268 Mon Sep 17 00:00:00 2001 From: gsq7474741 Date: Wed, 17 Nov 2021 20:15:38 +0800 Subject: [PATCH] add utils.plot_density_graph v0.2 --- paddle_quantum/utils.py | 4 ++-- test_and_documents/test.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/paddle_quantum/utils.py b/paddle_quantum/utils.py index 66a0651..5c2d68b 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 9423751..249ba61 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): -- GitLab