Skip to content

Commit

Permalink
Reduce imports on main tutorials (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
HGSilveri authored Feb 6, 2024
1 parent 824069a commit 16f566c
Show file tree
Hide file tree
Showing 4 changed files with 510 additions and 525 deletions.
49 changes: 26 additions & 23 deletions docs/source/intro_rydberg_blockade.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
"## Pulser's main features"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pulser\n",
"from pulser_simulation import QutipEmulator"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -38,11 +50,8 @@
},
"outputs": [],
"source": [
"from pulser import Register\n",
"from pulser.devices import DigitalAnalogDevice\n",
"\n",
"layers = 3\n",
"reg = Register.hexagon(layers)\n",
"reg = pulser.Register.hexagon(layers)\n",
"reg.draw(with_labels=False)"
]
},
Expand Down Expand Up @@ -73,14 +82,11 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"from pulser import Pulse\n",
"from pulser.waveforms import RampWaveform, BlackmanWaveform\n",
"\n",
"duration = 1000 # Typical: ~1 µsec\n",
"pulse = Pulse(\n",
" BlackmanWaveform(duration, np.pi), RampWaveform(duration, -5.0, 10.0), 0\n",
"pulse = pulser.Pulse(\n",
" amplitude=pulser.BlackmanWaveform(duration, np.pi),\n",
" detuning=pulser.RampWaveform(duration, -5.0, 10.0),\n",
" phase=0,\n",
")\n",
"pulse.draw()"
]
Expand All @@ -98,14 +104,14 @@
"metadata": {},
"outputs": [],
"source": [
"from pulser import Sequence\n",
"\n",
"reg = Register.rectangle(1, 2, spacing=8, prefix=\"atom\")\n",
"reg = pulser.Register.rectangle(1, 2, spacing=8, prefix=\"atom\")\n",
"reg.draw()\n",
"\n",
"pi_pulse = Pulse.ConstantDetuning(BlackmanWaveform(duration, np.pi), 0.0, 0.0)\n",
"pi_pulse = pulser.Pulse.ConstantDetuning(\n",
" pulser.BlackmanWaveform(duration, np.pi), 0.0, 0.0\n",
")\n",
"\n",
"seq = Sequence(reg, DigitalAnalogDevice)\n",
"seq = pulser.Sequence(reg, pulser.DigitalAnalogDevice)\n",
"\n",
"seq.declare_channel(\"ryd\", \"rydberg_local\", \"atom0\")\n",
"\n",
Expand Down Expand Up @@ -154,9 +160,6 @@
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"from pulser_simulation import QutipEmulator\n",
"\n",
"data = []\n",
"distances = np.linspace(6.5, 14, 7)\n",
"\n",
Expand All @@ -166,10 +169,10 @@
"\n",
"for i, R in enumerate(distances):\n",
" # Atom Register and Device\n",
" reg = Register.rectangle(1, 2, spacing=R, prefix=\"atom\")\n",
" reg = pulser.Register.rectangle(1, 2, spacing=R, prefix=\"atom\")\n",
"\n",
" # Pulse Sequence\n",
" seq = Sequence(reg, DigitalAnalogDevice)\n",
" seq = pulser.Sequence(reg, pulser.DigitalAnalogDevice)\n",
" seq.declare_channel(\"ryd\", \"rydberg_local\", \"atom0\")\n",
" seq.add(pi_pulse, \"ryd\")\n",
" seq.target(\"atom1\", \"ryd\")\n",
Expand Down Expand Up @@ -218,7 +221,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -232,7 +235,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
923 changes: 455 additions & 468 deletions tutorials/advanced_features/Backends for Sequence Execution.ipynb

Large diffs are not rendered by default.

31 changes: 14 additions & 17 deletions tutorials/creating_sequences.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"source": [
"import numpy as np\n",
"import pulser\n",
"from pprint import pprint\n",
"from pulser import Pulse, Sequence, Register"
"from pprint import pprint"
]
},
{
Expand All @@ -36,9 +35,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"L = 4\n",
Expand All @@ -47,7 +44,7 @@
"square *= 5\n",
"\n",
"qubits = dict(enumerate(square))\n",
"reg = Register(qubits)"
"reg = pulser.Register(qubits)"
]
},
{
Expand Down Expand Up @@ -83,7 +80,7 @@
"metadata": {},
"outputs": [],
"source": [
"reg2 = Register.from_coordinates(\n",
"reg2 = pulser.Register.from_coordinates(\n",
" square, prefix=\"q\"\n",
") # All qubit IDs will start with 'q'\n",
"reg2.draw()"
Expand All @@ -106,7 +103,7 @@
"metadata": {},
"outputs": [],
"source": [
"reg3 = Register.square(4, spacing=5) # 4x4 array with atoms 5 um apart\n",
"reg3 = pulser.Register.square(4, spacing=5) # 4x4 array with atoms 5 um apart\n",
"reg3.draw()"
]
},
Expand Down Expand Up @@ -134,7 +131,7 @@
"source": [
"from pulser.devices import DigitalAnalogDevice\n",
"\n",
"seq = Sequence(reg, DigitalAnalogDevice)"
"seq = pulser.Sequence(reg, DigitalAnalogDevice)"
]
},
{
Expand Down Expand Up @@ -238,7 +235,7 @@
"metadata": {},
"outputs": [],
"source": [
"simple_pulse = Pulse.ConstantPulse(200, 2, -10, 0)"
"simple_pulse = pulser.Pulse.ConstantPulse(200, 2, -10, 0)"
]
},
{
Expand Down Expand Up @@ -286,11 +283,11 @@
"metadata": {},
"outputs": [],
"source": [
"from pulser.waveforms import RampWaveform, BlackmanWaveform\n",
"\n",
"duration = 1000\n",
"amp_wf = BlackmanWaveform(duration, np.pi / 2) # Duration: 1000 ns, Area: pi/2\n",
"detuning_wf = RampWaveform(\n",
"amp_wf = pulser.BlackmanWaveform(\n",
" duration, np.pi / 2\n",
") # Duration: 1000 ns, Area: pi/2\n",
"detuning_wf = pulser.RampWaveform(\n",
" duration, -20, 20\n",
") # Duration: 1000ns, linear sweep from -20 to 20 rad/µs"
]
Expand Down Expand Up @@ -342,7 +339,7 @@
"metadata": {},
"outputs": [],
"source": [
"complex_pulse = Pulse(amp_wf, detuning_wf, phase=0)\n",
"complex_pulse = pulser.Pulse(amp_wf, detuning_wf, phase=0)\n",
"complex_pulse.draw()"
]
},
Expand Down Expand Up @@ -541,7 +538,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -555,7 +552,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
32 changes: 15 additions & 17 deletions tutorials/simulating_sequences.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
"metadata": {},
"outputs": [],
"source": [
"from pulser import Pulse, Sequence, Register\n",
"from pulser_simulation import QutipEmulator\n",
"from pulser.waveforms import BlackmanWaveform, RampWaveform\n",
"from pulser.devices import MockDevice\n",
"\n",
"import numpy as np\n",
"import qutip\n",
"import matplotlib.pyplot as plt"
"import matplotlib.pyplot as plt\n",
"\n",
"import pulser\n",
"from pulser_simulation import QutipEmulator"
]
},
{
Expand Down Expand Up @@ -50,7 +48,7 @@
"t_sweep = (delta_f - delta_0) / (2 * np.pi * 10) * 5000\n",
"\n",
"# Define a ring of atoms distanced by a blockade radius distance:\n",
"R_interatomic = MockDevice.rydberg_blockade_radius(U)\n",
"R_interatomic = pulser.MockDevice.rydberg_blockade_radius(U)\n",
"coords = (\n",
" R_interatomic\n",
" / (2 * np.tan(np.pi / L))\n",
Expand All @@ -62,7 +60,7 @@
" )\n",
")\n",
"\n",
"reg = Register.from_coordinates(coords, prefix=\"atom\")\n",
"reg = pulser.Register.from_coordinates(coords, prefix=\"atom\")\n",
"\n",
"reg.draw(blockade_radius=R_interatomic, draw_half_radius=True, draw_graph=True)"
]
Expand All @@ -87,17 +85,17 @@
"metadata": {},
"outputs": [],
"source": [
"rise = Pulse.ConstantDetuning(\n",
" RampWaveform(t_rise, 0.0, Omega_max), delta_0, 0.0\n",
"rise = pulser.Pulse.ConstantDetuning(\n",
" pulser.RampWaveform(t_rise, 0.0, Omega_max), delta_0, 0.0\n",
")\n",
"sweep = Pulse.ConstantAmplitude(\n",
" Omega_max, RampWaveform(t_sweep, delta_0, delta_f), 0.0\n",
"sweep = pulser.Pulse.ConstantAmplitude(\n",
" Omega_max, pulser.RampWaveform(t_sweep, delta_0, delta_f), 0.0\n",
")\n",
"fall = Pulse.ConstantDetuning(\n",
" RampWaveform(t_fall, Omega_max, 0.0), delta_f, 0.0\n",
"fall = pulser.Pulse.ConstantDetuning(\n",
" pulser.RampWaveform(t_fall, Omega_max, 0.0), delta_f, 0.0\n",
")\n",
"\n",
"seq = Sequence(reg, MockDevice)\n",
"seq = pulser.Sequence(reg, pulser.MockDevice)\n",
"seq.declare_channel(\"ising\", \"rydberg_global\")\n",
"\n",
"seq.add(rise, \"ising\")\n",
Expand Down Expand Up @@ -249,7 +247,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -263,7 +261,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 16f566c

Please sign in to comment.