From 288a97084b7c4a40696e5c536a89357e3830b735 Mon Sep 17 00:00:00 2001 From: James Nelson Date: Thu, 2 Jul 2026 16:22:28 +0100 Subject: [PATCH 1/4] fix 1d plotter --- qse/qbits.py | 5 ----- qse/vis/qbits.py | 17 ++++++----------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/qse/qbits.py b/qse/qbits.py index fcccb450..01522c74 100644 --- a/qse/qbits.py +++ b/qse/qbits.py @@ -539,7 +539,6 @@ def draw( show_labels=False, colouring=None, units=None, - equal_aspect=True, ): """ Visualize the positions of a set of qubits. @@ -560,9 +559,6 @@ def draw( Must have the same length as the number of Qubits. units : str, optional The units of distance. - equal_aspect : bool, optional - Whether to have the same scaling for the axes. - Defaults to True. See Also -------- @@ -574,7 +570,6 @@ def draw( show_labels=show_labels, colouring=colouring, units=units, - equal_aspect=equal_aspect, ) def repeat(self, rep): diff --git a/qse/vis/qbits.py b/qse/vis/qbits.py index 6736025e..d3b60acb 100644 --- a/qse/vis/qbits.py +++ b/qse/vis/qbits.py @@ -8,7 +8,7 @@ def draw_qbits( - qbits, radius=None, show_labels=False, colouring=None, units=None, equal_aspect=True + qbits, radius=None, show_labels=False, colouring=None, units=None ): """ Visualize the positions of a set of qubits. @@ -31,9 +31,6 @@ def draw_qbits( Must have the same length as the number of Qubits. units : str, optional The units of distance. - equal_aspect : bool, optional - Whether to have the same scaling for the axes. - Defaults to True. """ if colouring is not None: if len(colouring) != qbits.nqbits: @@ -53,15 +50,12 @@ def draw_qbits( draw_bonds = False fig = plt.figure() - projection = "3d" if qbits.dim == 3 else None - ax = fig.add_subplot(projection=projection) - if equal_aspect: - ax.set_aspect("equal") + ax = fig.add_subplot(projection="3d" if qbits.dim == 3 else None) if qbits.dim == 3: _draw_3d(qbits, draw_bonds, radius, rij, min_dist, ax) else: - _draw_2d( + _draw_1_or_2d( qbits, draw_bonds, radius, @@ -105,7 +99,7 @@ def _draw_3d(qbits, draw_bonds, radius, rij, min_dist, ax): ax.scatter(x, y, z, s=r**2, color=(0.1, c, 0.5), zorder=1, alpha=0.8) -def _draw_2d( +def _draw_1_or_2d( qbits, draw_bonds, radius, @@ -117,13 +111,14 @@ def _draw_2d( ax, ): ax.set_xlabel("x" + f" ({units})" if units is not None else "x") - ax.set_ylabel("y" + f" ({units})" if units is not None else "y") if qbits.dim == 2: x, y = qbits.positions.T + ax.set_ylabel("y" + f" ({units})" if units is not None else "y") else: x = qbits.positions.T.flatten() y = np.zeros(qbits.nqbits) + ax.set_yticks([]) # remove y-ticks for 1d plot. if draw_bonds: f_tol = 1.01 # fractional tolerance From dbb6fb41cca984be14ae80e509a99e79b2b840e4 Mon Sep 17 00:00:00 2001 From: James Nelson Date: Thu, 2 Jul 2026 16:30:42 +0100 Subject: [PATCH 2/4] notebooks --- docs/tutorials/generating_lattices.ipynb | 2 +- docs/tutorials/vqe_qiskit.ipynb | 58 +++++------------------- 2 files changed, 13 insertions(+), 47 deletions(-) diff --git a/docs/tutorials/generating_lattices.ipynb b/docs/tutorials/generating_lattices.ipynb index ac5ffb2b..880dc9e5 100644 --- a/docs/tutorials/generating_lattices.ipynb +++ b/docs/tutorials/generating_lattices.ipynb @@ -33,7 +33,7 @@ "outputs": [], "source": [ "qchain = qse.lattices.chain(lattice_spacing=3, repeats=10)\n", - "qchain.draw(radius=\"nearest\", equal_aspect=False)" + "qchain.draw(radius=\"nearest\")" ] }, { diff --git a/docs/tutorials/vqe_qiskit.ipynb b/docs/tutorials/vqe_qiskit.ipynb index d8c7b98f..dc1330b7 100644 --- a/docs/tutorials/vqe_qiskit.ipynb +++ b/docs/tutorials/vqe_qiskit.ipynb @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "116e033e", "metadata": {}, "outputs": [], @@ -37,12 +37,12 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "b1ec8bad", "metadata": {}, "outputs": [], "source": [ - "N = 10\n", + "N = 6\n", "J = 1.0\n", "h = 0.5\n", "spacing = 1.0\n", @@ -72,21 +72,10 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "id": "51b961bb", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "SparsePauliOp(['ZZIIIIIIII', 'IZZIIIIIII', 'IIZZIIIIII', 'IIIZZIIIII', 'IIIIZZIIII', 'IIIIIZZIII', 'IIIIIIZZII', 'IIIIIIIZZI', 'IIIIIIIIZZ', 'XIIIIIIIII', 'IXIIIIIIII', 'IIXIIIIIII', 'IIIXIIIIII', 'IIIIXIIIII', 'IIIIIXIIII', 'IIIIIIXIII', 'IIIIIIIXII', 'IIIIIIIIXI', 'IIIIIIIIIX'],\n", - " coeffs=[-1. +0.j, -1. +0.j, -1. +0.j, -1. +0.j, -1. +0.j, -1. +0.j, -1. +0.j,\n", - " -1. +0.j, -1. +0.j, -0.5+0.j, -0.5+0.j, -0.5+0.j, -0.5+0.j, -0.5+0.j,\n", - " -0.5+0.j, -0.5+0.j, -0.5+0.j, -0.5+0.j, -0.5+0.j])\n" - ] - } - ], + "outputs": [], "source": [ "pauli_op = hamiltonian.to_qiskit()\n", "print(pauli_op)" @@ -104,7 +93,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "7e8986ad", "metadata": {}, "outputs": [], @@ -116,12 +105,12 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "id": "55201685", "metadata": {}, "outputs": [], "source": [ - "ansatz = efficient_su2(num_qubits=N, reps=2, entanglement=\"linear\")\n", + "ansatz = efficient_su2(num_qubits=N, reps=1, entanglement=\"linear\")\n", "estimator = StatevectorEstimator()\n", "energies_list = []\n", "\n", @@ -144,43 +133,20 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "id": "94b26131", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "VQE ground state energy : -9.745759\n", - "Exact ground state energy: -9.76550395792718\n" - ] - } - ], + "outputs": [], "source": [ "ground_state = np.linalg.eigh(pauli_op.to_matrix())[0][0]\n", "print(f\"VQE ground state energy : {result.fun:.6f}\")\n", "print(f\"Exact ground state energy: {ground_state}\")" ] - }, - { - "cell_type": "markdown", - "id": "ab8e9a6d", - "metadata": {}, - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "87c3414d", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { "kernelspec": { - "display_name": "env_qse", + "display_name": "qse", "language": "python", "name": "python3" }, @@ -194,7 +160,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.11" + "version": "3.12.13" } }, "nbformat": 4, From b6bb186aea04b098fd5c2fd9a70a1764f7ab9a3b Mon Sep 17 00:00:00 2001 From: James Nelson Date: Thu, 2 Jul 2026 16:30:49 +0100 Subject: [PATCH 3/4] aspect --- qse/vis/qbits.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qse/vis/qbits.py b/qse/vis/qbits.py index d3b60acb..58a50ba6 100644 --- a/qse/vis/qbits.py +++ b/qse/vis/qbits.py @@ -71,6 +71,7 @@ def draw_qbits( def _draw_3d(qbits, draw_bonds, radius, rij, min_dist, ax): positions = qbits.positions + ax.set_aspect("equal") if draw_bonds: f_tol = 1.01 # fractional tolerance @@ -115,6 +116,8 @@ def _draw_1_or_2d( if qbits.dim == 2: x, y = qbits.positions.T ax.set_ylabel("y" + f" ({units})" if units is not None else "y") + ax.set_aspect("equal") + else: x = qbits.positions.T.flatten() y = np.zeros(qbits.nqbits) From e65cfbaa1d793fd3ed68789d9a87b7e72a676659 Mon Sep 17 00:00:00 2001 From: James Nelson Date: Thu, 2 Jul 2026 16:31:42 +0100 Subject: [PATCH 4/4] update --- qse/vis/qbits.py | 6 ++---- uv.lock | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/qse/vis/qbits.py b/qse/vis/qbits.py index 58a50ba6..37ae4789 100644 --- a/qse/vis/qbits.py +++ b/qse/vis/qbits.py @@ -7,9 +7,7 @@ rads = qse_palette["rads"] -def draw_qbits( - qbits, radius=None, show_labels=False, colouring=None, units=None -): +def draw_qbits(qbits, radius=None, show_labels=False, colouring=None, units=None): """ Visualize the positions of a set of qubits. @@ -121,7 +119,7 @@ def _draw_1_or_2d( else: x = qbits.positions.T.flatten() y = np.zeros(qbits.nqbits) - ax.set_yticks([]) # remove y-ticks for 1d plot. + ax.set_yticks([]) # remove y-ticks for 1d plot. if draw_bonds: f_tol = 1.01 # fractional tolerance diff --git a/uv.lock b/uv.lock index 8d23dc2b..4fe71dfb 100644 --- a/uv.lock +++ b/uv.lock @@ -4005,7 +4005,7 @@ wheels = [ [[package]] name = "qse" -version = "1.1.14" +version = "1.1.15" source = { editable = "." } dependencies = [ { name = "matplotlib" },