Guide to Lab Assignments

This setup guide will help you get started with using git and Jupyter to work on your lab assignments.

Selecting a lab partner

You will work with a partner on all labs after Lab 1. You must reselect a partner for each lab, so you may continue with the same person or choose a different partner the following week.

Complete the Lab Partner Selection Form. Only one student from each partnership needs to submit the form. You can change partners by resubmitting it; your latest submission will be used. If you do not submit the form, the instructor will assign you a partner.

Deadline: Lab partners cannot be changed after noon on the day the lab is released. The instructor may occasionally override requested partnerships.

Starting point code

We will be using GIT for all labs; if you need a refresher, check https://www.cs.swarthmore.edu/git/

You should be able to find all lab assignments in the course GitHub organization https://github.swarthmore.edu/orgs/CS63-Fall26/repositories

For each lab, a private repository will be created for you. The repository name will have the following format: lab01-SECTION-USERNAME. For partnered labs, one repostory will be shared between both partners.

Do the following steps to get the starting point code. Replace SECTION with your lab section and USERNAME with your own username. The $ represents the command prompt.

  1. Log in to one of the CS lab machines

  2. Make a new directory for this class and change into that directory:
    $ mkdir cs63
    $ cd cs63

  3. Clone the repository:
    $ git clone https://github.swarthmore.edu/CS63-Fall26/lab01-SECTION-USERNAME.git
    $ cd lab01-SECTION-USERNAME

Launching Jupyter

For this lab, we'll be using a development environment called Jupyter. The primary advantage of this platform is that it provides "notebooks," which are a way of interweaving Python code segments and their output with descriptive text, equations, graphs, and more.

Like any tool, Jupyter has its advantages and disadvantages, and we won't be using it for every lab this semester, but it's an excellent fit for the goals of this warmup lab.

To run Jupyter on one of our CS machines, you just need to do the following:

$ source /usr/swat/bin/CS63
$ jupyter-lab

The first command configures the Python environment so you'll have access to all the packages that we'll be using this semester; it needs to be run once (in any given terminal) before jupyter-lab. If you forget to do this, then jupyter-lab likely won't launch at all; if you get a command not found error, it's probably because you forgot to source the correct Python virtual environment.

The source command should actually change your command prompt, putting a (CS63) in the front; this is a reminder that it's worked correctly, and you can run Jupyter.

When you run jupyter-lab, it should launch a web browser (or open a tab in an existing browser window). There should be a file browser in the panel on the left; the root directory will be whatever directory you ran the jupyter-lab command in (if you followed the directions above, this should be your cs63 directory). Navigate to the Lab 0 directory and double click on the file named python_warmup.ipynb; doing so should open the notebook in the large panel on the right.

From here, all the remaining instructions are in the notebook; start reading at the top, and follow the directions in the notebook.

When you're finished, you can quit Jupyter by clicking the "File" menu and selecting "Shut Down" at the bottom. Alternatively, if you type [Ctrl-c] twice in the terminal you ran the command in, that will also shut down the program.

Note that if you want the (CS63) to go away, you can deactivate the virtual environment:

$ deactivate
However, this is not strictly necessary, since the virtual environment really only effects the versions of Python and Python libraries; all other commands should work normally regardless of whether you are in the CS63 environment or not.

When you're done, be sure to remember to use GIT to add/commit/push the changes you've made!

Submitting Your Work

To submit your work, you'll need to use Git to add, commit, and push your changes to the remote repository. Make sure to do this before the deadline. Any commits after the deadline will be considered late submissions.

Getting help on lab assignments

If you need help with your lab assignment, don't hesitate to ask your instructor or a teaching assistant for assistance. Please make sure to commit and push the latest version of your code before asking for help. This allows the instructor or teaching assistant to see your code and provide help.

Academic Integrity and AI usage policy

It it very important to follow the academic integrity and AI policies at all times as you work on your labs. Please review the policies in the course syllabus and on the course website.

AI-assisted coding is not permitted for lab assignments. When working on labs, you are expected to disable any generative AI tools in your development environment. Failure to do so will be considered a violation of the academic integrity policy. Please see the Academic Integrity section for more information.

(OPTIONAL) Python, Jupyter, NumPy, and MatPlotLib review

If you have not previously used Python, Jupyter, NumPy, or MatPlotLib, you are strongly encouraged to complete the warmup lab. The warmup lab should also be available on the course GitHub organization, and you can find it in the repository named Warmup-SECTION-USERNAME.

(OPTIONAL) Launching Jupyter Remotely

If you want to run Jupyter remotely (i.e. over an SSH connection, as opposed to on a machine you're physically logged in to), you'll need to add a couple of extra steps to the normal process. This is because Jupyter Lab is actually running a web server that your browser connects to; if the server and the browser are on the same machine, this happens automatically, but if you're connecting remotely you need to tell the two machines how to connect your local browser to the remote server.

The steps for running Jupyter remotely are as follows:

  1. Open a terminal on your local machine. This will let you use SSH to connect to the CS machines. All computers these days come with a terminal that has built in SSH; on Mac it's the "Terminal" app, on Windows it's the "Command Prompt" app, and on Linux it's whichever terminal emulator is your favorite (there's lots of options). The following commands should work the same way regardless of which terminal app you use.

  2. SSH to a CS machine, and specify a port to forward. Note that which port you use doesn't matter, so long as that port is not already in use. This means you shouldn't use a "standard" port number (e.g. 8080), and you need to avoid using the same port as another student logged in to the same machine (e.g. if everyone in class used "1234" there would be conflicts). I recommend using 63 (for our course) followed by the two-digit day-of-the-month of your birthday (as a random-ish two digit suffix), but you can come up with your own strategy.

    In the following command, XXXX stands for the port number, and USERNAME stands for your username:

    $ ssh -L localhost:XXXX:localhost:XXXX USERNAME@cslab.cs.swarthmore.edu

    This needs to be done on your machine! If you connect to a CS machine first and then run this command, it won't work; it's the initial connection from your personal machine to the CS network that needs to have the port-forwarding configured properly.

  3. Once you've logged in, you can run Jupyter similar to the way you normally would, except you need to tell it what port to use (this needs to match the port number you used when you ran the SSH command:

    $ source /usr/swat/bin/CS63
    $ jupyter-lab --port=XXXX --no-browser

    The first argument is the port number, replace XXXX with the port you're using. The second argument tells it not to automatically launch a web browser (which won't work over a standard SSH connection anyway).

  4. Once the Jupyter server is running, you should see some lines near the bottom that look something like:
        To access the server, open this file in a browser:
            file:///home/mitchell/.local/share/jupyter/runtime/jpserver-581164-open.html
        Or copy and paste one of these URLs:
            http://localhost:6311/lab?token=833c29214af009d97714c2a852333e47cb8a954dba7d9e7d
         or http://127.0.0.1:6311/lab?token=833c29214af009d97714c2a852333e47cb8a954dba7d9e7d
         
    The details will vary slightly (i.e. you won't have the same port and token number).

  5. Copy and paste one of these lines into the address bar in a web browser and hit enter; this should connect you to the Jupyter server running remotely. From that point on, everything should work just the same as it would if you were sitting in the lab.

  6. If you're working this way, remember that you'll need to do your GIT commands on the CS machine, not your local computer! One way to do this is to open a terminal inside Jupyter Lab; if you click the "File" menu and select "New Launcher", you can then select "Terminal" under the "Other" category. This will give you a terminal on whatever machine you ran the Jupyter Lab command on; you can do normal terminal things in it, including running GIT commands.