{
"cells": [
{
"cell_type": "markdown",
"id": "bc7840ba-518b-4fba-8a6d-16d368d94e59",
"metadata": {},
"source": [
"(schematic)=\n",
"# `schematic` - manual drawing\n",
"\n",
"This example demonstrates the basic functionality of the `schematic` module.\n",
"The schematic module is a simple wrapper around `matplotlib` that allows\n",
"programatically drawing diagrams, e.g. for tensor networks, in 2D and also\n",
"pseudo-3D. It is used as the backend for automatic drawing in\n",
"[TensorNetwork.draw](quimb.tensor.drawing.draw_tn), but it also useful for\n",
"making manual diagrams not associated with a tensor network. The main object\n",
"is the [`Drawing`](quimb.schematic.Drawing) class.\n",
"\n",
"\n",
"## Illustrative full examples\n",
"\n",
"The following examples are intended to be illustrative of a full drawing.\n",
"If you supply a dict of `presets` to `Drawing`, then you can provide default\n",
"styling for various elements simply by name.\n",
"\n",
"### 2D example"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "67d6b0f1-1943-48a6-8b2a-b6676f371080",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"from quimb import schematic\n",
"\n",
"presets = {\n",
" 'bond': {'linewidth': 3},\n",
" 'phys': {'linewidth': 1.5},\n",
" 'center': {\n",
" # `get_color` uses more colorblind friendly colors\n",
" 'color': schematic.get_color('orange'),\n",
" 'hatch': '/////',\n",
" },\n",
" 'left': {\n",
" 'color': schematic.get_color('bluedark'),\n",
" },\n",
" 'right': {\n",
" 'color': schematic.get_color('blue'),\n",
" },\n",
"}\n",
"\n",
"d = schematic.Drawing(presets=presets)\n",
"\n",
"L = 10\n",
"center = 5\n",
"\n",
"for i in range(10):\n",
" # draw tensor\n",
" d.circle((i, 0), preset=(\n",
" \"center\" if i == center else\n",
" \"left\" if i < center else\n",
" \"right\"\n",
" ))\n",
"\n",
" # draw physical index\n",
" d.line((i, 0), (i, -2/3), preset='phys')\n",
"\n",
" # draw virtual bond\n",
" if i + 1 < L:\n",
" d.line((i, 0), (i + 1, 0), preset='bond')\n",
"\n",
" # draw isometric conditions\n",
" if i != center:\n",
" d.arrowhead((i, -2/3), (i, 0), preset='phys')\n",
" if i < center - 1:\n",
" d.arrowhead((i, 0), (i + 1, 0), preset='bond')\n",
" if i > center + 1:\n",
" d.arrowhead((i, 0), (i - 1, 0), preset='bond')\n",
"\n",
"# label the left\n",
"if center > 0:\n",
" d.text((center - 1, 0.8), 'LEFT')\n",
" d.patch_around([(i, 0) for i in range(center)], radius=0.5)\n",
"\n",
"# label pair\n",
"if center + 1 < L:\n",
" d.patch_around_circles(\n",
" (center, 0), 0.3,\n",
" (center + 1, 0), 0.3,\n",
" facecolor=(.2, .8, .5, .4),\n",
" )\n",
"\n",
"# label the right\n",
"if center + 2 < L:\n",
" d.text((center + 2, 0.8), 'RIGHT')\n",
" d.patch_around([(i, 0) for i in range(center + 2, L)], radius=0.5)"
]
},
{
"cell_type": "markdown",
"id": "2da67ed9-a3d4-4622-9dac-cb8b44f6e2cc",
"metadata": {},
"source": [
"### Pseudo-3D example\n",
"\n",
"If you supply 3D coordinates to `Drawing` methods then the objects will be\n",
"mapped by the axonometric projection to 2D and given appropriate z-ordering.\n",
"The projection and orientation can be controlled in the `Drawing` constructor."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3f190069-28f8-4ca8-845f-9422d00dcb9f",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"image/svg+xml": [
"