Show the simulation result.
Parameters:
-
data
(Union[ndarray, list])
–
-
mode
(str)
–
The mode of given data, should be one of [state_vector, density_matrix]
Source code in QuICT/tools/display/simulation_draw.py
| def amplitude_drawer(data: np.ndarray):
""" Show the simulation result.
Args:
data Union[np.ndarray, list]: The result data.
mode (str): The mode of given data, should be one of [state_vector, density_matrix]
"""
plt.figure(figsize=(10, 10), dpi=80)
plt.subplot(1, 1, 1)
data = np.abs(data)
N = data.size
qubits = int(np.log2(N))
mode = "state_vector" if data.ndim == 1 else "density_matrix"
if mode == "state_vector":
indexes = ["{0:0b}".format(i).zfill(qubits) for i in range(N)]
data_no0, indexes_no0 = remove_zero_value(data, indexes)
hist = plt.bar(indexes_no0, data_no0, label="State Vector")
plt.ylabel("Amplitude")
elif mode == "density_matrix":
ax = plt.subplot(projection='3d')
x = [i for i in range(int(np.sqrt(N)))]
for xx, yy in product(x, x):
ax.bar3d(
xx, yy, 0, dx=1, dy=1, dz=data[xx, yy]
)
plt.ylabel("State")
plt.xlabel("State")
plt.show()
|