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

Found issue in qsphere, need to heavily improve rendering in/organiza… #74

Merged
merged 3 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/visualize/bloch.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def bloch(
y = 1 * np.sin(theta) * np.sin(phi)
z = 1 * np.cos(theta)
xs, ys, zs = [0, x], [0, y], [0, z]
ax.plot3D(xs, ys, zs, color=_accent)
ax.plot3D(xs, ys, zs, color=_accent, markevery=100)
ax.scatter(xs[1], ys[1], zs[1], s=5, color=_accent)
ax.text(xs[1] * 1.15, ys[1] * 1.15, zs[1] * 1.15, "|ψ⟩", color=_text)
plt.tight_layout()
Expand Down
8 changes: 5 additions & 3 deletions src/visualize/probability.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import matplotlib.pyplot as plt
from .base.graph import graph
from ..tools import probability
from ..tools import probability as prob
from ..tools.base import convert_state
import numpy as np


Expand All @@ -11,9 +12,10 @@ def probability(
show: bool = True,
darkmode: bool = True,
):
num_qubits = np.log2(len(state))

num_qubits = int(np.log2(len(convert_state(state))))
state_list = [format(i, "b").zfill(num_qubits) for i in range(2**num_qubits)]
percents = [i * 100 for i in probability(state)]
percents = [i * 100 for i in prob(state)]
if darkmode:
_text = "white"
_accent = "#39c0ba"
Expand Down
13 changes: 6 additions & 7 deletions src/visualize/q_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from matplotlib.cm import ScalarMappable
from .base.sphere import sphere
from ..tools import probability, amplitude, phase_angle
from ..tools import probability, amplitude, phaseangle


def hamming_distance(l1: str, l2: str):
Expand Down Expand Up @@ -61,9 +61,9 @@ def q_sphere(
show: bool = True,
darkmode: bool = True,
):
num_qubits = int(np.log2((len(quantumstate))))
num_qubits = int(np.log2((len(quantumstate.state))))
probs = probability(quantumstate)
angle = phase_angle(quantumstate)
angle = phaseangle(quantumstate)
state_list = [format(i, "b").zfill(num_qubits) for i in range(2**num_qubits)]
prob_dict = {state_list[i]: probs[i] for i in range(len(state_list))}
phase_dict = {state_list[i]: angle[i] for i in range(len(state_list))}
Expand All @@ -77,12 +77,10 @@ def q_sphere(
_accent = "black"
_background = "white"
ax = sphere(_background)

coords = get_coords(num_qubits, lat_vals)
ham_states = [item for sublist in lat_vals for item in sublist]
colors = plt.get_cmap("hsv")
norm = plt.Normalize(0, np.pi * 2)

for i, j in zip(coords, ham_states):
cur_prob = prob_dict[j]
cur_phase = phase_dict[j]
Expand All @@ -91,8 +89,9 @@ def q_sphere(
ax.plot3D(x, y, z, color=colors(norm(cur_phase)))
ax.scatter(x[1], y[1], z[1], s=5, color=colors(norm(cur_phase)))
ax.text(x[1] * 1.15, y[1] * 1.15, z[1] * 1.15, f"|{j}>", color=_text)

cbar = plt.colorbar(ScalarMappable(cmap=colors, norm=norm), shrink=0.55)
cbar = plt.colorbar(
plt.cm.ScalarMappable(cmap=colors, norm=norm), ax=plt.gca(), shrink=0.55
)
cbar.set_label("Phase Angle", rotation=270, labelpad=15, color=_accent)
cbar.set_ticks([2 * np.pi, (3 * np.pi) / 2, np.pi, np.pi / 2, 0])
cbar.ax.yaxis.set_tick_params(color=_text)
Expand Down
11 changes: 7 additions & 4 deletions src/visualize/state_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from matplotlib.cm import ScalarMappable
from matplotlib.colors import rgb2hex
from .base.graph import graph
from ..tools import amplitude, phase_angle
from ..tools import amplitude, phaseangle
from ..tools.base import convert_state


def state_vector(
Expand All @@ -13,10 +14,10 @@ def state_vector(
show: bool = False,
darkmode: bool = True,
):
num_qubits = int(np.log2(circuit.size))
num_qubits = int(np.log2(len(convert_state(circuit))))
state_list = [format(i, "b").zfill(num_qubits) for i in range(2**num_qubits)]
amplitutes = amplitude(circuit, num_qubits)
phase_angles = phase_angle(circuit, num_qubits)
phase_angles = phaseangle(circuit)
if darkmode:
_text = "white"
_accent = "#39c0ba"
Expand All @@ -34,7 +35,9 @@ def state_vector(
plt.xlabel("Computational basis states", color=_accent)
plt.ylabel("Amplitutde", labelpad=5, color=_accent)
plt.title("State Vector", pad=10, color=_accent)
cbar = plt.colorbar(ScalarMappable(cmap=colors, norm=norm))
cbar = plt.colorbar(
plt.cm.ScalarMappable(cmap=colors, norm=norm), ax=plt.gca(), shrink=0.55
)
cbar.set_label("Phase Angle", rotation=270, labelpad=10, color=_accent)
cbar.set_ticks([2 * np.pi, (3 * np.pi) / 2, np.pi, np.pi / 2, 0])
cbar.ax.yaxis.set_tick_params(color=_text)
Expand Down
Loading