Skip to content

Commit 5b954c8

Browse files
committed
using spyder
1 parent eae4960 commit 5b954c8

1 file changed

Lines changed: 126 additions & 101 deletions

File tree

docs/day2/IDEs.rst

Lines changed: 126 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -500,118 +500,116 @@ Jupyter Notebook is a sibling to other notebook authoring applications under the
500500
* **Exporting notebooks** 📤 to different formats (HTML, PDF, Markdown, etc.) can be done via "File" > "Download as" or "Export Notebook As".
501501
* **Using magic commands** ✨ like ``%timeit``, ``%matplotlib inline``, ``%load``, and ``%%writefile`` can enhance your workflow significantly.
502502

503-
.. tip::
503+
.. admonition:: Keyboard shortcuts
504504
:class: dropdown
505505

506-
.. admonition:: Keyboard shortcuts
507-
:class: dropdown
506+
- ``Shift + Enter``: Run the current cell and move to the next one
507+
- ``Ctrl + Enter``: Run the current cell and stay in it
508+
- ``Alt + Enter``: Run the current cell and insert a new one below
509+
- ``Esc``: Enter command mode
510+
- ``Enter``: Enter edit mode
511+
- In command mode:
512+
- ``A``: Insert cell above
513+
- ``B``: Insert cell below
514+
- ``DD``: Delete current cell
515+
- ``M``: Change cell to Markdown
516+
- ``Y``: Change cell to Code
517+
- ``Shift + Up/Down``: Select multiple cells
518+
519+
.. admonition:: Magic commands
520+
:class: dropdown
508521

509-
- ``Shift + Enter``: Run the current cell and move to the next one
510-
- ``Ctrl + Enter``: Run the current cell and stay in it
511-
- ``Alt + Enter``: Run the current cell and insert a new one below
512-
- ``Esc``: Enter command mode
513-
- ``Enter``: Enter edit mode
514-
- In command mode:
515-
- ``A``: Insert cell above
516-
- ``B``: Insert cell below
517-
- ``DD``: Delete current cell
518-
- ``M``: Change cell to Markdown
519-
- ``Y``: Change cell to Code
520-
- ``Shift + Up/Down``: Select multiple cells
521-
522-
.. admonition:: Magic commands
523-
:class: dropdown
524-
525-
Use these to speed up development, debugging, and exploration inside notebooks:
522+
Use these to speed up development, debugging, and exploration inside notebooks:
526523

527-
- ``%lsmagic`` — list available line and cell magics.
528-
.. code-block:: python
524+
- ``%lsmagic`` — list available line and cell magics.
525+
.. code-block:: python
529526
530-
%lsmagic
527+
%lsmagic
531528
532-
- Timing snippets
533-
- ``%time`` — time a single statement.
534-
.. code-block:: python
529+
- Timing snippets
530+
- ``%time`` — time a single statement.
531+
.. code-block:: python
535532
536-
%time sum(range(100000))
533+
%time sum(range(100000))
537534
538-
- ``%timeit`` / ``%%timeit`` — run repeated timings for more robust measurements.
539-
.. code-block:: python
535+
- ``%timeit`` / ``%%timeit`` — run repeated timings for more robust measurements.
536+
.. code-block:: python
540537
541-
%timeit sum(range(1000))
538+
%timeit sum(range(1000))
542539
543-
%%timeit
544-
a = [i*i for i in range(1000)]
545-
sum(a)
540+
%%timeit
541+
a = [i*i for i in range(1000)]
542+
sum(a)
546543
547-
- ``%run`` — run a Python script and load its variables into the notebook namespace.
548-
.. code-block:: python
544+
- ``%run`` — run a Python script and load its variables into the notebook namespace.
545+
.. code-block:: python
549546
550-
%run scripts/my_analysis.py
547+
%run scripts/my_analysis.py
551548
552-
- ``%load`` — load a script or URL into the current cell (useful for editing before execution).
553-
.. code-block:: python
549+
- ``%load`` — load a script or URL into the current cell (useful for editing before execution).
550+
.. code-block:: python
554551
555-
%load scripts/snippet.py
552+
%load scripts/snippet.py
556553
557-
- Auto-reload for iterative development
558-
.. code-block:: python
554+
- Auto-reload for iterative development
555+
.. code-block:: python
559556
560-
%load_ext autoreload
561-
%autoreload 2
562-
# Now imported modules are reloaded automatically when changed.
557+
%load_ext autoreload
558+
%autoreload 2
559+
# Now imported modules are reloaded automatically when changed.
563560
564-
- Variable inspection and namespace control
565-
.. code-block:: python
561+
- Variable inspection and namespace control
562+
.. code-block:: python
566563
567-
%who # names only
568-
%whos # detailed table of variables
569-
%reset -f # clear user namespace
564+
%who # names only
565+
%whos # detailed table of variables
566+
%reset -f # clear user namespace
570567
571-
- Interactive debugger on exceptions
572-
.. code-block:: python
568+
- Interactive debugger on exceptions
569+
.. code-block:: python
573570
574-
%pdb on
575-
# Raises into the interactive debugger when exceptions occur
571+
%pdb on
572+
# Raises into the interactive debugger when exceptions occur
576573
577-
- Persist variables between sessions
578-
.. code-block:: python
574+
- Persist variables between sessions
575+
.. code-block:: python
579576
580-
mydata = {"a": 1}
581-
%store mydata
582-
# In a later session: %store -r mydata
577+
mydata = {"a": 1}
578+
%store mydata
579+
# In a later session: %store -r mydata
583580
584-
- Installing packages from within the notebook (preferred over !pip)
585-
.. code-block:: python
581+
- Installing packages from within the notebook (preferred over !pip)
582+
.. code-block:: python
586583
587-
%pip install matplotlib seaborn
584+
%pip install matplotlib seaborn
588585
589-
- Run shell blocks or single shell commands
590-
.. code-block:: bash
586+
- Run shell blocks or single shell commands
587+
.. code-block:: bash
591588
592-
%%bash
593-
echo "This runs in a bash subshell"
594-
ls -l
589+
%%bash
590+
echo "This runs in a bash subshell"
591+
ls -l
595592
596-
# single-line shell:
597-
!pwd
593+
# single-line shell:
594+
!pwd
598595
599-
- IPython profiling and line profiling (if extensions are installed)
600-
.. code-block:: python
596+
- IPython profiling and line profiling (if extensions are installed)
597+
.. code-block:: python
601598
602-
%prun my_function() # run profiler
603-
%lprun -f my_function my_function() # requires line_profiler extension
599+
%prun my_function() # run profiler
600+
%lprun -f my_function my_function() # requires line_profiler extension
604601
605-
- Show available magics and help
606-
.. code-block:: python
602+
- Show available magics and help
603+
.. code-block:: python
607604
608-
%magic # detailed magic help
609-
%timeit? # doc for a specific magic
605+
%magic # detailed magic help
606+
%timeit? # doc for a specific magic
610607
611608
612609
.. challenge::
613610

614611
* Try Jupyter interface with the following Notebook Code.
612+
* Start an interactive session with 4-8 cores and 1-2 hr walltime.
615613
* `cd` into your project directory and start `Jupyter Notebook` or `JupyterLab` as described in previous sections.
616614
* Create a new Python 3 notebook.
617615

@@ -665,6 +663,7 @@ Jupyter Notebook is a sibling to other notebook authoring applications under the
665663
.. admonition:: Resources
666664
:class: dropdown
667665

666+
- Official Jupyter documentation: `Jupyter Documentation <https://jupyter-notebook.readthedocs.io/en/latest/notebook.html>`_
668667
- Jupyter notebook `examples from original documentation <https://nbviewer.org/github/jupyter/notebook/tree/main/docs/source/examples/Notebook/>`_
669668
- You can also check the lesson about `Jupyter on compute nodes <https://uppmax.github.io/R-python-julia-matlab-HPC/python/jupyter.html>`_ in our "Introduction to running R, Python and Julia in HPC workshop"
670669
- Documentation about `Jupyter on HPC2N <https://docs.hpc2n.umu.se/tutorials/jupyter/>`_
@@ -751,53 +750,79 @@ Spyder
751750
Features
752751
########
753752

754-
When you open Spyder, you should see something like the figure below. There should be a large pane on the left for code, and two smaller panes on the right. Each of the 3 panes have their own button with 3 horizontal lines (the menu button or "burger icon") in the top right, each with additional configuration options for those panes.
753+
When you open Spyder you will see a three-pane layout similar to other scientific IDEs: a large Editor on the left, and one or more utility panes on the right and bottom. The exact arrangement can be customised and saved as a layout.
755754

756755
.. admonition:: Spyder interface
757756
:class: dropdown
758757

759758
.. figure:: ../img/cosmos-on-demand-spyder.png
760759

760+
Main panes and useful tabs
761761

762-
The top right pane has several useful tabs.
762+
* Editor (left) 📝
763+
* Edit multiple files in tabs : use the Run toolbar (green ▶️) to run the current file or selection.
764+
* You can mark cells with ``# %%`` (or ``# %%%`` for multi level cells) and run cells interactively.
765+
* Use the burger menu on the editor pane to split, undock or save layout.
763766

764-
* **Help** displays information about commands and starts up with a message instructing you on how to use it.
765-
* **Variable explorer** shows a table of currently defined variables, their datatypes, and their current values at runtime. It updates every time you either run a script file or run a command in the IPython console.
766-
* **Files** shows the file tree for your current working directory
767-
* Depending on the version , there may also be a **Plots** tab for displaying and adjusting graphics produced with, e.g. Matplotlib.
767+
* Utility pane (Top-right) 🧰
768+
* Help 🔍: documentation and contextual help for the symbol under the cursor.
769+
* Variable explorer 🧾 : table view of in-memory variables with types and values; inspect, edit or remove variables.
770+
* Files 📂 : file browser for the current working directory.
771+
* Plots 📈 : interactive plots panel (may be a tab in recent versions); can be undocked to a separate window for better interaction.
768772

769-
You can move any of these tabs into separate windows by clicking the menu (burger) button and selecting "Undock". This is especially helpful for the plotting tab.
773+
* Console and History (Bottom-right) 🖥️
774+
* IPython console(s) : interactive Python connected to the currently selected kernel/environment.
775+
* History log : previously executed commands from the console.
770776

771-
The bottom right pane shows the IPython console and a history tab. The IPython console is your Python command line, and runs in your current working directory unless changed with ``os.chdir()``. The default path is whatever directory you were in when you launched Spyder, but that can be changed in Preferences. If you run a script file that you've saved to a different directory using the green arrow icon on the menu ribbon, the IPython console will switch your working directory to the one containing that script. The history tab stores the last 500 lines of code excuted in the IPython console.
777+
.. admonition:: Quick Tips
778+
:class: dropdown
779+
780+
* Run workflow
781+
* Save your script and click the Run button to execute it in the IPython console. Running a saved file will switch the console working directory to the file's location (configurable in Preferences).
782+
* Run selection or a cell from the editor to test snippets without running the whole file.
783+
* Debugging
784+
* Set breakpoints in the editor gutter and launch the debugger from the Run menu or toolbar to step through code and inspect variables.
785+
* Plotting
786+
* Undock the Plots tab or set the IPython console graphics backend to "Automatic" or a GUI backend in Preferences so figures open in separate windows and remain interactive.
787+
* Multiple consoles/kernels
788+
* You can open multiple IPython consoles and assign each a different interpreter or conda environment. This is useful for testing code against different environments.
789+
790+
* Notes
791+
* Undock panels (burger menu → Undock) for a multi-monitor workflow or to resize plots independently.
792+
* If Spyder appears too small on ThinLinc or high-DPI screens, enable "Set custom high-DPI scaling" in Preferences → General → Interface.
793+
* Prefer launching Spyder from a graphical session (ThinLinc / On-demand desktop). Running it on a login node without a desktop may not work or be unsupported.
794+
795+
.. admonition:: Configuring Spyder
796+
:class: dropdown
772797

773-
Most of the icons along the top menu bar under the verbal menu are running and debugging commands. You can hover over any of them to see what they do.
798+
**Font and icon sizes.** If you are on Thinlinc and/or on a Linux machine, Spyder may be uncomfortably small the first time you open it. To fix this,
774799

800+
#. Click the icon shaped like a wrench (Preferences) or click "Tools" and then "Preferences". A popup should open with a menu down the left side, and the "General" menu option should already be selected (if not, select it now).
801+
#. You should see a tab titled "Interface" that has options that mention "high-DPI scaling". Select "Set custom high-DPI scaling" and enter the factor by which you'd like the text and icons to be magnified (recommend a number from 1.5 to 2).
802+
#. Click "Apply". If the popup in the next step doesn't appear immediately, then click "OK".
803+
#. A pop-up will appear that says you need to restart to view the changes and asks if you want to restart now. Click "Yes" and wait. The terminal may flash some messages like ``QProcess: Destroyed while process ("/hpc2n/eb/software/Python/3.8.2-GCCcore-9.3.0/bin/python") is still running."``, but it should restart within a minute or so. Don't interrupt it or you'll have to start over.
775804

776-
Configuring Spyder
777-
##################
805+
The text and icons should be rescaled when it reopens, and should stay rescaled even if you close and reopen Spyder, as long as you're working in the same session.
778806

779-
**Font and icon sizes.** If you are on Thinlinc and/or on a Linux machine, Spyder may be uncomfortably small the first time you open it. To fix this,
807+
**(Optional but recommended) Configure plots to open in separate windows.** In some versions of Spyder, there is a separate Plotting Pane that you can click and drag out of its dock so you can resize figures as needed, but if you don't see that, you will probably want to change your graphics backend. The default is usually "Inline", which is usually too small and not interactive. To change that,
780808

781-
#. Click the icon shaped like a wrench (Preferences) or click "Tools" and then "Preferences". A popup should open with a menu down the left side, and the "General" menu option should already be selected (if not, select it now).
782-
#. You should see a tab titled "Interface" that has options that mention "high-DPI scaling". Select "Set custom high-DPI scaling" and enter the factor by which you'd like the text and icons to be magnified (recommend a number from 1.5 to 2).
783-
#. Click "Apply". If the popup in the next step doesn't appear immediately, then click "OK".
784-
#. A pop-up will appear that says you need to restart to view the changes and asks if you want to restart now. Click "Yes" and wait. The terminal may flash some messages like ``QProcess: Destroyed while process ("/hpc2n/eb/software/Python/3.8.2-GCCcore-9.3.0/bin/python") is still running."``, but it should restart within a minute or so. Don't interrupt it or you'll have to start over.
809+
#. Click the icon shaped like a wrench (Preferences) or click "Tools" and then "Preferences" to open the Preferences popup.
810+
#. In the menu sidebar to the left, click "IPython console". The box to the right should then have 4 tabs, of which the second from the left is "Graphics" (see figure below).
811+
#. Click "Graphics" and find the "Graphics backend" box below. In that box, next to "Backend" there will be a dropdown menu that probably says "Inline". Click the dropdown and select "Automatic".
812+
#. Click "Apply" and then "OK" to exit.
785813

786-
The text and icons should be rescaled when it reopens, and should stay rescaled even if you close and reopen Spyder, as long as you're working in the same session.
814+
.. admonition:: Spyder interface
815+
:class: dropdown
787816

788-
**(Optional but recommended) Configure plots to open in separate windows.** In some versions of Spyder, there is a separate Plotting Pane that you can click and drag out of its dock so you can resize figures as needed, but if you don't see that, you will probably want to change your graphics backend. The default is usually "Inline", which is usually too small and not interactive. To change that,
817+
.. figure:: ../img/cosmos-on-demand-spyder-preferences.png
789818

790-
#. Click the icon shaped like a wrench (Preferences) or click "Tools" and then "Preferences" to open the Preferences popup.
791-
#. In the menu sidebar to the left, click "IPython console". The box to the right should then have 4 tabs, of which the second from the left is "Graphics" (see figure below).
792-
#. Click "Graphics" and find the "Graphics backend" box below. In that box, next to "Backend" there will be a dropdown menu that probably says "Inline". Click the dropdown and select "Automatic".
793-
#. Click "Apply" and then "OK" to exit.
819+
Now, graphics should appear in their own popup that has menu options to edit and save the content.
794820

795-
.. admonition:: Spyder interface
821+
.. admonition:: Resources
796822
:class: dropdown
797823

798-
.. figure:: ../img/cosmos-on-demand-spyder-preferences.png
824+
- Official Spyder documentation: `Spyder Documentation <https://docs.spyder-ide.org/current/panes/index.html>`_
799825

800-
Now, graphics should appear in their own popup that has menu options to edit and save the content.
801826

802827
VS Code
803828
--------

0 commit comments

Comments
 (0)