From ad302fb9fae281ddb1808efcfe52481302472304 Mon Sep 17 00:00:00 2001 From: Alex Maldonado Date: Mon, 18 Nov 2024 10:39:12 -0500 Subject: [PATCH] Formatting updates --- LICENSE_INFO.md | 34 ++-- docs/basics/colab.md | 187 ------------------ .../2. Variables and Collections.md | 1 - docs/external/ultimate/advanced/async.md | 1 - docs/external/ultimate/advanced/benchmark.md | 1 - .../ultimate/advanced/context_manager.md | 1 - docs/external/ultimate/advanced/date_time.md | 5 +- docs/external/ultimate/advanced/decorator.md | 1 - .../ultimate/advanced/file_handling.md | 1 - docs/external/ultimate/advanced/meta_class.md | 1 - docs/external/ultimate/advanced/mixin.md | 1 - docs/external/ultimate/advanced/mocking.md | 1 - docs/external/ultimate/advanced/mro.md | 1 - docs/external/ultimate/advanced/regex.md | 1 - docs/external/ultimate/advanced/thread.md | 9 +- docs/external/ultimate/advanced/weak_ref.md | 1 - docs/external/ultimate/classes/basic_class.md | 1 - .../ultimate/classes/encapsulation.md | 1 - .../ultimate/classes/exception_class.md | 1 - docs/external/ultimate/classes/inheritance.md | 1 - .../ultimate/classes/iterator_class.md | 1 - .../external/ultimate/data_structures/list.md | 1 - docs/intro/.pages | 3 +- docs/intro/colab/.pages | 6 + docs/intro/colab/cells/index.md | 36 ++++ docs/intro/colab/index.md | 17 ++ docs/intro/colab/kernel/index.md | 65 ++++++ docs/intro/colab/opening-files/index.md | 35 ++++ docs/intro/colab/reproducibility/index.md | 20 ++ mkdocs.yml | 9 +- pyproject.toml | 26 +-- 31 files changed, 208 insertions(+), 262 deletions(-) delete mode 100644 docs/basics/colab.md create mode 100644 docs/intro/colab/.pages create mode 100644 docs/intro/colab/cells/index.md create mode 100644 docs/intro/colab/index.md create mode 100644 docs/intro/colab/kernel/index.md create mode 100644 docs/intro/colab/opening-files/index.md create mode 100644 docs/intro/colab/reproducibility/index.md diff --git a/LICENSE_INFO.md b/LICENSE_INFO.md index 900c6f7..42de72a 100644 --- a/LICENSE_INFO.md +++ b/LICENSE_INFO.md @@ -39,21 +39,21 @@ m. **You** means the individual or entity exercising the Licensed Rights under t a. ***License grant.*** - 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: + 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: A. reproduce and Share the Licensed Material, in whole or in part; and B. produce, reproduce, and Share Adapted Material. - 2. **Exceptions and Limitations.** For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. + 2. **Exceptions and Limitations.** For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. - 3. **Term.** The term of this Public License is specified in Section 6(a). + 3. **Term.** The term of this Public License is specified in Section 6(a). - 4. **Media and formats; technical modifications allowed.** The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. + 4. **Media and formats; technical modifications allowed.** The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. - 5. **Downstream recipients.** + 5. **Downstream recipients.** A. **Offer from the Licensor – Licensed Material.** Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. @@ -61,15 +61,15 @@ a. ***License grant.*** C. **No downstream restrictions.** You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. - 6. **No endorsement.** Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). + 6. **No endorsement.** Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). b. ***Other rights.*** - 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. + 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. - 2. Patent and trademark rights are not licensed under this Public License. + 2. Patent and trademark rights are not licensed under this Public License. - 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties. + 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties. ## Section 3 – License Conditions. @@ -77,7 +77,7 @@ Your exercise of the Licensed Rights is expressly made subject to the following a. ***Attribution.*** - 1. If You Share the Licensed Material (including in modified form), You must: + 1. If You Share the Licensed Material (including in modified form), You must: A. retain the following if it is supplied by the Licensor with the Licensed Material: @@ -95,21 +95,21 @@ a. ***Attribution.*** C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. - 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. + 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. - 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. + 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. b. ***ShareAlike.*** In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply. -1. The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-SA Compatible License. +1. The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-SA Compatible License. -2. You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. +2. You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material. -3. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply. +3. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply. ## Section 4 – Sui Generis Database Rights. @@ -141,9 +141,9 @@ However, if You fail to comply with this Public License, then Your rights under b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: - 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or + 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or - 2. upon express reinstatement by the Licensor. + 2. upon express reinstatement by the Licensor. For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. diff --git a/docs/basics/colab.md b/docs/basics/colab.md deleted file mode 100644 index f253d05..0000000 --- a/docs/basics/colab.md +++ /dev/null @@ -1,187 +0,0 @@ -# Google Colab - -Managing local Python installations can be troublesome with a large class. -Different versions, dependencies, and system setups could mean it runs on your computer but not elsewhere. -To minimize these issues, we will be using [Google Colab](https://colab.google/) to write, run, and distribute Python code in [Jupyter Notebooks](https://jupyter.org/). - -## Features - -- Google Colab runs in the cloud on Google's servers. - This means you don't need to install any software on your local machine, and you can access it from anywhere with an internet connection. -- One of the notable features of Google Colab is that it provides free access to Graphics Processing Units (GPUs) and Tensor Processing Units (TPUs). - This can be especially beneficial for machine learning tasks that require significant computational power. -- Multiple users can collaborate in real-time on a Colab Notebook. This makes it easy for teams to work together on coding projects, share insights, and provide feedback. -- Colab integrates seamlessly with Google Drive. - You can save your Colab Notebooks directly to your Google Drive, share them, and access them from any device. -- Colab Notebooks run on virtual machines in the cloud, and your session state persists as long as the virtual machine is active. - However, if there is inactivity for too long, the session may be disconnected. - -## Opening files in Colab - -When you see a ![colab logo](/img/launchy/colab.svg){ width=18px } symbol in the upper right corner on a page of this website, you can click on it to open up that file directly in [Google Colab](https://colab.google/). - -!!! example - - Go to [this page](../../intro/regression/introduction.ipynb) to see an example. - If you click ![colab logo](/img/launchy/colab.svg){ width=18px } then you will be taken [here](https://colab.research.google.com/github/oasci/pitt-biosc1540-2024s-website/blob/main/biosc1540/modules/intro/regression/introduction.ipynb). - -How does this work? -Well, [Google Colab](https://colab.google/) has an import mechanism for Jupyter Notebooks in [GitHub](https://github.com/) repositories. -Adding an import link is all it takes. - -When you open up our Jupyter notebooks in Google colab, you will be met with this screen. - -
-![](/img/colab/gui.svg){ width=600 } -
- -Jupyter notebooks are made up of cells which can be thought of as paragraphs that can change types. -[Markdown](https://www.markdownguide.org/) is simply text like you would put in a Word document, email, etc. -The only difference is how you specify things like a list, link, etc. - -When you see a `[ ]` on the left with a greyed out background, this is a Python cell. -You can put any Python code here and run it. -We will get to this [later](#cells). - -When working on Jupyter notebooks from this website, you should always save a copy to your Google Drive. - -To run Python code, you have to connect to Google's servers. -When you click this button, it will initiate a connection to Google's servers and will look like this once it is done. - -
-![](/img/colab/kernel-running.png){ width=200 } -
- -## Downloading - -In most cases, you will need to upload your assignment to Gradescope as a Python file (`.py`). - -
-![](/img/colab/save-py.png){ width=600 } -
- -This will download your Jupyter Notebook as a Python script that my autograder can use. -It will comment out all markdown cells and then run your Python code from top to bottom. - -## Cells - -A Jupyter notebook consists of a sequence of cells. -The flow of a notebook is sequential from top to bottom. -You enter code into an input cell, and when you run the cell, the notebook runs the code and prints the output of the computation to an output cell. - -For example, we can look at the following Python code. - -```python -print("Your message here!") -``` - -This Python code should print the string "Your message here!" once we run it. -The figure directly below shows the ▷ on the left, which means we can run the Python code in that cell. - -
-![](/img/colab/cell.svg){ width=300 } -
- -Once we run this, you would see the figure below. - -
-![](/img/colab/cell-ran.png){ width=300 } -
- -You can tell that the Python cell was ran **at some point** by the ✓ to the right with no errors. -The `0s` below the ✓ just tells you how many seconds it took to run. -We can also see the cell output contains `Your message here!`. -If you make any changes to this cell, you have to run it again. - -Do not worry, you do not have to keep clicking a bunch of ▷ to run all of your cells. -We have some shortcuts: - -- Windows: ++ctrl+enter++ -- Mac: ++cmd+enter++ -- Linux: ++ctrl+enter++ - -## Python kernel - -You may hear me use the term "kernel" or "Python kernel" frequently throughout the course. -It can be thought of as a mini computer running in the background of your computer. -By running Python code in a Jupyter notebook, you are giving instructions to the kernel, the kernel does some processing, then it will give you any outputs you requested. - -Stopping and starting the kernel is very similar to restarting your own computer. -You get a fresh kernel each time, and this is a good first step for troubleshooting any issues. - -When you open up our Jupyter notebooks in Google colab, you will be met with this screen. - -
-![](/img/colab/runtime.svg){ width=600 } -
- -You can restart the kernel from the `Runtime` menu at the top left with two options: - -- Restart session: This is essentially turning the kernel on and back on again. - However, this does not automatically run all of your Python code. -- Restart session and run all: This restarts the kernel, but then also runs all of your Python cells from top to bottom. - Usually you want to use this one. - -### Persistent - -One crucial aspect of Jupyter notebooks to be aware of is that the kernel is persistent. -This means that it keeps track of everything you ran while connected to Google's servers. -Variables, functions, and computations performed in one Python cell are available in other Python cells—before or after. -For example, suppose I have the following three cells: - -**1**: - -```python -testing = True -``` - -**2**: - -```python -print(testing, course) -``` - -**3**: - -```python -course = "computational biology" -``` - -If I ran cell **1** and then tried to run cell **2**, Python would give me an error because `course` is not defined. -However, if I then ran cell **3**, then ran cell **2** again it would work! -This is because the whole Python kernel shares memory; changing anything would update the shared memory and would affect Python cells that run after. - -### Inspecting - -Because all cells share the same kernel, we can actually view (i.e., inspect) what variables we have and what they are defined as. -Suppose I define three lists like so. - -
-![](/img/colab/vars.png){ width=600 } -
- -If I click on the $\{x\}$ symbol on the left, Jupyter will show me all of the variable names, types, values, and other information. - -
-![](/img/colab/vars-inspect.png){ width=600 } -
- -## Reproducibility - -As mentioned above, the version of Python can affect its reproducibility. -We include the following code as the first code cell. - -```python -import sys -IN_COLAB = 'google.colab' in sys.modules -if IN_COLAB: - !sudo apt-get update -y > /dev/null 2>&1 - !sudo apt-get install python3.11 python3.11-dev python3.11-distutils libpython3.11-dev > /dev/null 2>&1 - !sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2 > /dev/null 2>&1 -``` - -All this does is check if the Jupyter Notebook is running and install the version of Python used to develop this course: 3.11. - -You can technically remove this. -The version of Python usually has small changes that are backward compatible. -The main issue is the dependencies that we install; some have very specific version requirements that could affect which versions get installed. diff --git a/docs/external/learn-python-y-minutes/2. Variables and Collections.md b/docs/external/learn-python-y-minutes/2. Variables and Collections.md index cc1be27..014117f 100644 --- a/docs/external/learn-python-y-minutes/2. Variables and Collections.md +++ b/docs/external/learn-python-y-minutes/2. Variables and Collections.md @@ -1,6 +1,5 @@ # 2. Variables and Collections - ```python # Python has a print function print("I'm Python. Nice to meet you!") # => I'm Python. Nice to meet you! diff --git a/docs/external/ultimate/advanced/async.md b/docs/external/ultimate/advanced/async.md index 22b3801..4a8e1d0 100644 --- a/docs/external/ultimate/advanced/async.md +++ b/docs/external/ultimate/advanced/async.md @@ -5,7 +5,6 @@ jobs. In the real world, it takes time for a scheduler to start a job (i.e. hit an API endpoint, ask the operating system for resources) so we assume that starting a job has some intrinsic delay. - ```python import asyncio from dataclasses import dataclass diff --git a/docs/external/ultimate/advanced/benchmark.md b/docs/external/ultimate/advanced/benchmark.md index b7d73d0..20e4a6e 100644 --- a/docs/external/ultimate/advanced/benchmark.md +++ b/docs/external/ultimate/advanced/benchmark.md @@ -5,7 +5,6 @@ Benchmarking is an approach that helps developers use profiling metrics and their code intuition to optimize programs further. This module uses cProfile to compare the performance of two functions with each other. - ```python import cProfile import io diff --git a/docs/external/ultimate/advanced/context_manager.md b/docs/external/ultimate/advanced/context_manager.md index f4898a3..5d41db0 100644 --- a/docs/external/ultimate/advanced/context_manager.md +++ b/docs/external/ultimate/advanced/context_manager.md @@ -5,7 +5,6 @@ can manage are files, database connections and sockets. In this module, we simulate how a context manager can handle open and close operations of a file-like object called StringIO. - ```python from contextlib import contextmanager from io import StringIO diff --git a/docs/external/ultimate/advanced/date_time.md b/docs/external/ultimate/advanced/date_time.md index ddf5486..08388ad 100644 --- a/docs/external/ultimate/advanced/date_time.md +++ b/docs/external/ultimate/advanced/date_time.md @@ -9,20 +9,19 @@ personal device. Once we use `datetime` objects for web applications that are deployed globally, it's important to know the offset that `datetime` objects are aligned to before processing them. For more on `datetime`: -https://docs.python.org/3/library/datetime.html + Backend developers address this by storing time fields with offsets aligned with the UTC (Coordinated Universal Time) timezone. As a result, time fields can be displayed in any timezone - at any moment. For more on UTC: -https://en.wikipedia.org/wiki/Coordinated_Universal_Time + In this module, we will show the difference between offset-naive and offset-aware `datetime` objects. We will also highlight the builtin UTC timezone and show how it can be used to make the default `datetime` object more powerful. - ```python from datetime import datetime, timezone diff --git a/docs/external/ultimate/advanced/decorator.md b/docs/external/ultimate/advanced/decorator.md index 99dd717..6081feb 100644 --- a/docs/external/ultimate/advanced/decorator.md +++ b/docs/external/ultimate/advanced/decorator.md @@ -4,7 +4,6 @@ This module shows how a simple "encryption" function for one string can be decorated to work with a collection of strings. Note that the decorator handles nested collections with the use of recursion. - ```python from functools import wraps diff --git a/docs/external/ultimate/advanced/file_handling.md b/docs/external/ultimate/advanced/file_handling.md index 5c40acd..9e70ca4 100644 --- a/docs/external/ultimate/advanced/file_handling.md +++ b/docs/external/ultimate/advanced/file_handling.md @@ -7,7 +7,6 @@ Python provides various ways to work with files. We can use the builtin 'open' function to open files in different modes like reading ('r'), writing ('w'), and appending ('a'). - ```python import os diff --git a/docs/external/ultimate/advanced/meta_class.md b/docs/external/ultimate/advanced/meta_class.md index 8b6f69b..9729d25 100644 --- a/docs/external/ultimate/advanced/meta_class.md +++ b/docs/external/ultimate/advanced/meta_class.md @@ -3,7 +3,6 @@ Metaclass are used to modify a class as it is being created at runtime. This module shows how a metaclass can add database attributes and tables to "logic-free" model classes for the developer. - ```python from abc import ABC diff --git a/docs/external/ultimate/advanced/mixin.md b/docs/external/ultimate/advanced/mixin.md index b6925d3..932d3e3 100644 --- a/docs/external/ultimate/advanced/mixin.md +++ b/docs/external/ultimate/advanced/mixin.md @@ -5,7 +5,6 @@ module, we have one request handler interface and two request handler mixins to illustrate how mixins can make our lives easier when defining concrete classes. - ```python from abc import ABC, abstractmethod from dataclasses import dataclass diff --git a/docs/external/ultimate/advanced/mocking.md b/docs/external/ultimate/advanced/mocking.md index 97d7e90..7d4e8c1 100644 --- a/docs/external/ultimate/advanced/mocking.md +++ b/docs/external/ultimate/advanced/mocking.md @@ -4,7 +4,6 @@ depends on an external system or external resources for it to work properly. This module shows how to use mocking to modify an application server so that it is easier to test. - ```python from collections import Counter from unittest.mock import MagicMock, PropertyMock, patch diff --git a/docs/external/ultimate/advanced/mro.md b/docs/external/ultimate/advanced/mro.md index 11c70b2..d8e0893 100644 --- a/docs/external/ultimate/advanced/mro.md +++ b/docs/external/ultimate/advanced/mro.md @@ -4,7 +4,6 @@ to determine which method will be run by a class instance. This module shows how the MRO is useful for the classic diamond problem where classes B and C depend on class A, and class D depends on classes B and C. - ```python class BasePlayer: """Base player.""" diff --git a/docs/external/ultimate/advanced/regex.md b/docs/external/ultimate/advanced/regex.md index cf7f096..a884b5c 100644 --- a/docs/external/ultimate/advanced/regex.md +++ b/docs/external/ultimate/advanced/regex.md @@ -4,7 +4,6 @@ them is difficult but Python provides a package for us to use them easily. This module shows a few examples of how to use the `re` package to search predefined text snippets stored in module-level constants. - ```python import re diff --git a/docs/external/ultimate/advanced/thread.md b/docs/external/ultimate/advanced/thread.md index 16d270c..dc276cd 100644 --- a/docs/external/ultimate/advanced/thread.md +++ b/docs/external/ultimate/advanced/thread.md @@ -8,8 +8,8 @@ reading the code below. Here are some resources to learn more about threads: -https://realpython.com/intro-to-python-threading/ -https://docs.python.org/3/library/threading.html + + Python threads are not suitable for CPU-heavy tasks in the CPython interpreter due to the GIL. To address this, we typically resort to @@ -17,9 +17,8 @@ forking processes or running C externally. Here are some resources to learn more about the GIL: -https://realpython.com/python-gil/ -https://wiki.python.org/moin/GlobalInterpreterLock - + + ```python import time diff --git a/docs/external/ultimate/advanced/weak_ref.md b/docs/external/ultimate/advanced/weak_ref.md index 5346478..3c4ed8f 100644 --- a/docs/external/ultimate/advanced/weak_ref.md +++ b/docs/external/ultimate/advanced/weak_ref.md @@ -4,7 +4,6 @@ more easily. This module shows how it can be used to keep a server registry up-to-date as it explicitly sets up and implicitly tears down servers as the program enters and leaves a function scope. - ```python import weakref from uuid import uuid4 diff --git a/docs/external/ultimate/classes/basic_class.md b/docs/external/ultimate/classes/basic_class.md index 3b073dc..5d278ad 100644 --- a/docs/external/ultimate/classes/basic_class.md +++ b/docs/external/ultimate/classes/basic_class.md @@ -3,7 +3,6 @@ A class is made up of methods and state. This allows code and data to be combined as one logical entity. This module defines a basic car class, creates a car instance and uses it for demonstration purposes. - ```python from inspect import isfunction, ismethod, signature diff --git a/docs/external/ultimate/classes/encapsulation.md b/docs/external/ultimate/classes/encapsulation.md index 72eced9..87133d6 100644 --- a/docs/external/ultimate/classes/encapsulation.md +++ b/docs/external/ultimate/classes/encapsulation.md @@ -5,7 +5,6 @@ within a class. This prevents users from directly accessing and modifying such attributes from outside the class. Instead, users must use methods to access and modify attributes. - ```python import secrets diff --git a/docs/external/ultimate/classes/exception_class.md b/docs/external/ultimate/classes/exception_class.md index b51f00c..4e1a4db 100644 --- a/docs/external/ultimate/classes/exception_class.md +++ b/docs/external/ultimate/classes/exception_class.md @@ -5,7 +5,6 @@ anticipated, and specify the exception class they intend to throw. This module defines a handful of custom exception classes and shows how they can be used in the context of a function. - ```python class CustomError(Exception): """Custom class of errors. diff --git a/docs/external/ultimate/classes/inheritance.md b/docs/external/ultimate/classes/inheritance.md index feb9f1b..3bd862f 100644 --- a/docs/external/ultimate/classes/inheritance.md +++ b/docs/external/ultimate/classes/inheritance.md @@ -5,7 +5,6 @@ functionality. This module defines a basic vehicle class, creates a car class that inherits from vehicle, then creates a truck class that inherits from car and use it for demonstration purposes. - ```python from inspect import isfunction, ismethod diff --git a/docs/external/ultimate/classes/iterator_class.md b/docs/external/ultimate/classes/iterator_class.md index 2b40488..5b062e6 100644 --- a/docs/external/ultimate/classes/iterator_class.md +++ b/docs/external/ultimate/classes/iterator_class.md @@ -4,7 +4,6 @@ This module defines an employee iterator class that iterates through each employee in a hierarchy one-by-one. This module also shows how a similar approach can be achieved with a generator function. - ```python # Module-level constants _ITERATION_MESSAGE = "Cyclic loop detected" diff --git a/docs/external/ultimate/data_structures/list.md b/docs/external/ultimate/data_structures/list.md index b8bf197..94d558b 100644 --- a/docs/external/ultimate/data_structures/list.md +++ b/docs/external/ultimate/data_structures/list.md @@ -4,7 +4,6 @@ Lists are a sequence of values that can be modified at runtime. This module shows how lists are created, iterated, accessed, extended and shortened. - ```python def main(): # This is a list of strings where diff --git a/docs/intro/.pages b/docs/intro/.pages index b742103..fc15523 100644 --- a/docs/intro/.pages +++ b/docs/intro/.pages @@ -1,3 +1,4 @@ nav: - Introduction: index.md - - Running Python: run + - Google Colab: colab +# - Running Python: run diff --git a/docs/intro/colab/.pages b/docs/intro/colab/.pages new file mode 100644 index 0000000..19d3207 --- /dev/null +++ b/docs/intro/colab/.pages @@ -0,0 +1,6 @@ +nav: + - Colab: index.md + - Opening files: opening-files + - Cells: cells + - Kernel: kernel + - Reproducibility: reproducibility diff --git a/docs/intro/colab/cells/index.md b/docs/intro/colab/cells/index.md new file mode 100644 index 0000000..fb15877 --- /dev/null +++ b/docs/intro/colab/cells/index.md @@ -0,0 +1,36 @@ +# Cells + +A Jupyter notebook consists of a sequence of cells. +The flow of a notebook is sequential from top to bottom. +You enter code into an input cell, and when you run the cell, the notebook runs the code and prints the output of the computation to an output cell. + +For example, we can look at the following Python code. + +```python +print("Your message here!") +``` + +This Python code should print the string "Your message here!" once we run it. +The figure directly below shows the ▷ on the left, which means we can run the Python code in that cell. + +
+![](/img/colab/cell.svg){ width=300 } +
+ +Once we run this, you would see the figure below. + +
+![](/img/colab/cell-ran.png){ width=300 } +
+ +You can tell that the Python cell was ran **at some point** by the ✓ to the right with no errors. +The `0s` below the ✓ just tells you how many seconds it took to run. +We can also see the cell output contains `Your message here!`. +If you make any changes to this cell, you have to run it again. + +Do not worry, you do not have to keep clicking a bunch of ▷ to run all of your cells. +We have some shortcuts: + +- Windows: ++ctrl+enter++ +- Mac: ++cmd+enter++ +- Linux: ++ctrl+enter++ diff --git a/docs/intro/colab/index.md b/docs/intro/colab/index.md new file mode 100644 index 0000000..6acf32b --- /dev/null +++ b/docs/intro/colab/index.md @@ -0,0 +1,17 @@ +# Google Colab + +Managing local Python installations can be troublesome with a large class. +Different versions, dependencies, and system setups could mean it runs on your computer but not elsewhere. +To minimize these issues, we will be using [Google Colab](https://colab.google/) to write, run, and distribute Python code in [Jupyter Notebooks](https://jupyter.org/). + +## Features + +- Google Colab runs in the cloud on Google's servers. + This means you don't need to install any software on your local machine, and you can access it from anywhere with an internet connection. +- One of the notable features of Google Colab is that it provides free access to Graphics Processing Units (GPUs) and Tensor Processing Units (TPUs). + This can be especially beneficial for machine learning tasks that require significant computational power. +- Multiple users can collaborate in real-time on a Colab Notebook. This makes it easy for teams to work together on coding projects, share insights, and provide feedback. +- Colab integrates seamlessly with Google Drive. + You can save your Colab Notebooks directly to your Google Drive, share them, and access them from any device. +- Colab Notebooks run on virtual machines in the cloud, and your session state persists as long as the virtual machine is active. + However, if there is inactivity for too long, the session may be disconnected. diff --git a/docs/intro/colab/kernel/index.md b/docs/intro/colab/kernel/index.md new file mode 100644 index 0000000..00ef961 --- /dev/null +++ b/docs/intro/colab/kernel/index.md @@ -0,0 +1,65 @@ +# Python kernel + +You may hear me use the term "kernel" or "Python kernel" frequently throughout the course. +It can be thought of as a mini computer running in the background of your computer. +By running Python code in a Jupyter notebook, you are giving instructions to the kernel, the kernel does some processing, then it will give you any outputs you requested. + +Stopping and starting the kernel is very similar to restarting your own computer. +You get a fresh kernel each time, and this is a good first step for troubleshooting any issues. + +When you open up our Jupyter notebooks in Google colab, you will be met with this screen. + +
+![](/img/colab/runtime.svg){ width=600 } +
+ +You can restart the kernel from the `Runtime` menu at the top left with two options: + +- Restart session: This is essentially turning the kernel on and back on again. + However, this does not automatically run all of your Python code. +- Restart session and run all: This restarts the kernel, but then also runs all of your Python cells from top to bottom. + Usually you want to use this one. + +## Persistence + +One crucial aspect of Jupyter notebooks to be aware of is that the kernel is persistent. +This means that it keeps track of everything you ran while connected to Google's servers. +Variables, functions, and computations performed in one Python cell are available in other Python cells—before or after. +For example, suppose I have the following three cells: + +**1**: + +```python +testing = True +``` + +**2**: + +```python +print(testing, course) +``` + +**3**: + +```python +course = "computational biology" +``` + +If I ran cell **1** and then tried to run cell **2**, Python would give me an error because `course` is not defined. +However, if I then ran cell **3**, then ran cell **2** again it would work! +This is because the whole Python kernel shares memory; changing anything would update the shared memory and would affect Python cells that run after. + +## Inspecting + +Because all cells share the same kernel, we can actually view (i.e., inspect) what variables we have and what they are defined as. +Suppose I define three lists like so. + +
+![](/img/colab/vars.png){ width=600 } +
+ +If I click on the $\{x\}$ symbol on the left, Jupyter will show me all of the variable names, types, values, and other information. + +
+![](/img/colab/vars-inspect.png){ width=600 } +
diff --git a/docs/intro/colab/opening-files/index.md b/docs/intro/colab/opening-files/index.md new file mode 100644 index 0000000..a30dceb --- /dev/null +++ b/docs/intro/colab/opening-files/index.md @@ -0,0 +1,35 @@ +# Opening files + +When you see a ![colab logo](/img/launchy/colab.svg){ width=18px } symbol in the upper right corner on a page of this website, you can click on it to open up that file directly in [Google Colab](https://colab.google/). + +!!! example + + Go to [this page](../../intro/regression/introduction.ipynb) to see an example. + If you click ![colab logo](/img/launchy/colab.svg){ width=18px } then you will be taken [here](https://colab.research.google.com/github/oasci/pitt-biosc1540-2024s-website/blob/main/biosc1540/modules/intro/regression/introduction.ipynb). + +How does this work? +Well, [Google Colab](https://colab.google/) has an import mechanism for Jupyter Notebooks in [GitHub](https://github.com/) repositories. +Adding an import link is all it takes. + +When you open up our Jupyter notebooks in Google colab, you will be met with this screen. + +
+![](/img/colab/gui.svg){ width=600 } +
+ +Jupyter notebooks are made up of cells which can be thought of as paragraphs that can change types. +[Markdown](https://www.markdownguide.org/) is simply text like you would put in a Word document, email, etc. +The only difference is how you specify things like a list, link, etc. + +When you see a `[ ]` on the left with a greyed out background, this is a Python cell. +You can put any Python code here and run it. +We will get to this [later](#cells). + +When working on Jupyter notebooks from this website, you should always save a copy to your Google Drive. + +To run Python code, you have to connect to Google's servers. +When you click this button, it will initiate a connection to Google's servers and will look like this once it is done. + +
+![](/img/colab/kernel-running.png){ width=200 } +
diff --git a/docs/intro/colab/reproducibility/index.md b/docs/intro/colab/reproducibility/index.md new file mode 100644 index 0000000..db1afa2 --- /dev/null +++ b/docs/intro/colab/reproducibility/index.md @@ -0,0 +1,20 @@ + +# Reproducibility + +As mentioned above, the version of Python can affect its reproducibility. +We include the following code as the first code cell. + +```python +import sys +IN_COLAB = 'google.colab' in sys.modules +if IN_COLAB: + !sudo apt-get update -y > /dev/null 2>&1 + !sudo apt-get install python3.11 python3.11-dev python3.11-distutils libpython3.11-dev > /dev/null 2>&1 + !sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2 > /dev/null 2>&1 +``` + +All this does is check if the Jupyter Notebook is running and install the version of Python used to develop this course: 3.11. + +You can technically remove this. +The version of Python usually has small changes that are backward compatible. +The main issue is the dependencies that we install; some have very specific version requirements that could affect which versions get installed. diff --git a/mkdocs.yml b/mkdocs.yml index 22e0099..8c54e91 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -54,23 +54,16 @@ validation: absolute_links: warn unrecognized_links: warn -# Options need to be indented twice for some reason? plugins: - search - autorefs - material-plausible - table-reader - - mkdocstrings: - handlers: - python: - paths: ["python-bc"] - options: - annotations_path: brief - docstring_style: google - mkdocs-jupyter: no_input: False include_requirejs: true include_source: false + execute: false remove_tag_config: remove_input_tags: - hide_code diff --git a/pyproject.toml b/pyproject.toml index 35cdf80..0afe526 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,26 +40,6 @@ ruff = ">=0.7.1,<0.8" bump-my-version = ">=0.27.0,<0.28" [tool.pixi.tasks] -mdlint = { cmd = ["markdownlint-cli2", '"**/*.{md,markdown}"', "--fix", "--config", ".markdownlint.yaml", "||", "true"] } -isort = { cmd = ["isort", "--settings-path", "pyproject.toml", "./content"] } -black = { cmd = ["black", "--config", "pyproject.toml", "./content"] } -format = { depends-on = ["mdlint", "isort", "black"] } -docs = { cmd = ["rm", "-rf", "./public/", "&&", "mkdocs", "build", "-d", "public/"] } -serve = { cmd = ["mkdocs", "serve"] } - -[tool.bumpversion] -current_version = "2023.10.29" -tag = true -commit = true - -[tool.poetry-dynamic-versioning] -enable = true -vcs = "git" -format-jinja = "{%- if distance == 0 -%}{{ serialize_pep440(base) }}{%- else -%}{{ serialize_pep440(base, post=distance) }}{%- endif -%}" - -[build-system] -requires = [ - "poetry-core>=1.0.0", - "poetry-dynamic-versioning>=1.0.0,<2.0.0", -] -build-backend = "poetry_dynamic_versioning.backend" +docs = { cmd = ["mkdocs", "build", "-d", "public/", "--clean"] } +docs-cache = { cmd = ["mkdocs", "build", "-d", "public/"] } +serve = { cmd = ["mkdocs", "serve", "-a", "localhost:29847", "--open", "--dirty"] }