Skip to content
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 docs/tutorials/generating_lattices.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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\")"
]
},
{
Expand Down
58 changes: 12 additions & 46 deletions docs/tutorials/vqe_qiskit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "116e033e",
"metadata": {},
"outputs": [],
Expand All @@ -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",
Expand Down Expand Up @@ -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)"
Expand All @@ -104,7 +93,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "7e8986ad",
"metadata": {},
"outputs": [],
Expand All @@ -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",
Expand All @@ -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"
},
Expand All @@ -194,7 +160,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.11"
"version": "3.12.13"
}
},
"nbformat": 4,
Expand Down
5 changes: 0 additions & 5 deletions qse/qbits.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ def draw(
show_labels=False,
colouring=None,
units=None,
equal_aspect=True,
):
"""
Visualize the positions of a set of qubits.
Expand All @@ -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
--------
Expand All @@ -574,7 +570,6 @@ def draw(
show_labels=show_labels,
colouring=colouring,
units=units,
equal_aspect=equal_aspect,
)

def repeat(self, rep):
Expand Down
22 changes: 9 additions & 13 deletions qse/vis/qbits.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
rads = qse_palette["rads"]


def draw_qbits(
qbits, radius=None, show_labels=False, colouring=None, units=None, equal_aspect=True
):
def draw_qbits(qbits, radius=None, show_labels=False, colouring=None, units=None):
"""
Visualize the positions of a set of qubits.

Expand All @@ -31,9 +29,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:
Expand All @@ -53,15 +48,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,
Expand All @@ -77,6 +69,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
Expand Down Expand Up @@ -105,7 +98,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,
Expand All @@ -117,13 +110,16 @@ 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")
ax.set_aspect("equal")

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
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading