02-Tooling#

  • Python

  • datahub

  • Jupyter Notebooks

  • Anaconda

  • Academic Integrity

Logistics#

  • Today:

    • go to coding lab!

    • tonight CL1 is due (effort graded!)

    • if you’re nervous about this you can play with the Practice Assignment first (we will later in class)

  • Soon:

    • Fill out the #FinAid survey on Canvas

  • Mon Jan 15:

    • Deadline for doing the precourse survey

    • NO LECTURE – MLK holiday

This notebook will guide through the tools you will need for class materials and assignments, and how to get them.

This is the join code for an iClicker in this class: let’s test it… https://join.iclicker.com/ALQL

Class Question #1#

How excited are you for COGS 18?

  • A. Super excited!

  • B. The most excited!

  • C. Couldn’t be more excited!

  • D. I love the smell of programming in the morning!

Prerequisites#

This course and associated materials do not presume any prior knowledge of Python, or programming in general.

To work with the course materials, you will need make sure you have access to the tools tools described here on datahub.

It will be helpful for the final project if they are also installed on the computer you will be using.

None of the materials are computationally heavy.

What do you need?#

  • Required: Access to datahub

    • Python (datahub uses python v3.9)

    • Jupyter Notebooks

Python is a programming language, whose development is led by the Python Software Foundation (PSF).
The official Python organization website is available here.

Python#

  • Versions: there are different versions of Python.

    • We will be using 3.9 on datahub (>3.6 required)

  • Packages: Python includes a “base set” of code (the standard library), and an extensive ecosystem of third party packages

    • In this course, we will largely focus on the standard library

    • For access to other packages when we need them, we will use Anaconda

Jupyter notebooks are a way to intermix code, outputs and plain text. They run in a web browser, and connect to a kernel to be able to execute code.
The official Jupyter website is available here.

JupyterHub#

JupyterHub allows Jupyter notebooks to be shared across multiple users.
The official JupyterHub website is available here.

Datahub#

UCSD hosts its version of JupyterHub and calls it datahub. This is what you’ll be using in class.

It is available here: http://datahub.ucsd.edu

When to use Datahub?#

  • Course Lecture Slides

  • CodingLabs

  • Assignments

  • Final Project/Exam

Lecture Slides:#

Once you’ve logged into datahub, click on the the following link: https://datahub.ucsd.edu/hub/user-redirect/git-pull?repo=https://github.com/COGS18/LectureNotes-COGS18&urlpath=tree/LectureNotes-COGS18/&branch=main

(This link is also on the Canvas home page.)

CodingLabs & Assignments:#

  • Fetch & complete on datahub

  • do not change file names

  • do not copy cells provided

  • adding cells is allowed!

  • print() statements encouraged

  • For Submission:

    • Before you click submit, make sure it’s the thing you want to submit

    • You must click submit.

    • Always check that the CodingLab/Assignment/Exam shows up under “submitted assignments”

    • You can submit as many times as you want

    • We only have access to your most recent submission

    • If you submit past the deadline, we will only have access to your late submission

A note about: Timezones#

  • Due Dates are in UTC

  • All deadlines are 11:59 PM PST/PDT

Timezones

TimeZones: https://www.timeanddate.com/time/map/

Jupyter Notebooks#

  • Markdown

  • code cells

Jupyter notebooks are a way to combine executable code, code outputs, and text into one connected file.
The official documentation from project Jupyter is available here and they also have some example notebooks here .
For more useful information, check out Jupyter Notebooks tips & tricks , and more information on how notebooks work.

Cells#

The main organizational structure of the notebook are cells.

Cells are an independent ‘unit’. When you click into a cell, you can ‘run’ it by clicking Shift + Enter, or by pressing the play (Run) button above.

Cells come in different types for writing different things - mainly, text or code.

Markdown Cells#

Cells, can be markdown (text), like this one.

A brief note about Markdown. It’s a way to specify all formatting within the text itself.

For example, italicized text can be specified with an underscore or single asterisks.

Bold text requires two underccores or two asterisks.

Class Question #2#

What does three underscores around text accomplish?

  • A) bold

  • B) italicize

  • C) bold + italicize

  • D) normal text

  • E) I’m lost

you can write/edit your markdown text here to determine the answer to the question

Markdown Headers#

Headers are specified with a pound sign#

The more pound signs, the smaller the header#

But it’s still larger#

than just plain text.

Lists are also possible:

  • item 1

  • item 2

  • item 3

  1. numbered item

  2. item 2

  3. item 3

Class Question #3#

What would happen if I specified a numbered list but put the same number before each list item?

  • A) the list would have the same number before each item

  • B) markdown would still format it with sequential numbers

  • C) markdown wouldn’t know it was a list

  • D) normal text with everything on a single line

  • E) I’m lost

test it out down here to see…

list item list item list item

Code Cells#

Whenever you’re writing code, you’ll want to be sure the cell is set to be a code cell

# Cell can also be code.
a = 1
b = 2
# Cells can also have output, that gets printed out below the cell.
c = a - b
print(c)
# If you execute a cell with just a variable name in it, it will also get printed
c

Running Cells#

  • The numbers in the square brackets to the left of a cell show which cells have been run, and in what order.

    • An asterisk (*) means that the cell is currently running

    • You do not need to run cells in order! This is useful for flexibly testing and developing code.

Coding time#

Write code that outputs the value ‘6’

## YOUR CODE HERE

Class Question #4#

Which of the following best describes you?

  • A) I completed the task.

  • B) I tried but wasn’t able to complete the task.

  • C) I am not sure where to start.

Accessing Documentation#

Jupyter has useful shortcuts. Add a single ? after a function or class get a window with the documentation, or a double ?? to pull up the source code.
# For example, execute this cell to see the documentation for the 'abs'
abs?

Autocomplete#

Jupyter also has tab complete capacities, which can autocomplete what you are typing, and/or be used to explore what code is available. (Note: Some of this functionality is limited on datahub.)
# Move your cursor to the end of the line, press tab, and a drop menu will appear showing all possible completions
ra
# If there is only one option, tab-complete will auto-complete what you are typing
ran

Let’s do the practice assignment now…#

An in class demo of how to deal with the Assignments on Datahub. Don’t worry if we don’t get this far in lecture, because then we will do it in Coding Lab / Discussion section

Academic Integrity#

We’ve had some issues in the past, so we’re trying to be incredibly explicit this quarter so that we’re all on the same page. (And, because this differs from some other courses.)

Correction: It was for one exam; it was not constant. And it was 6/100 (which is 6% of the class!)

I came into this class knowing absolutely nothing about coding. Being in this position, I have made it my goal to go above and beyond in learning about programming languages that I am unfamiliar with because I personally like a challenge and I love learning new things.

Because coding does not come naturally to me, I plan WAY ahead of time as to when I need to sit down, uninterrupted, to really learn, make mistakes, and test out the code I write in assignments. For example, I plan DAYS ahead of time as to when I need to sit down and complete assignments. Again, because coding does not come naturally to me, I spend on average 2 hours more than the median hours/time spent listed. Not only do I spend hours completing assignments to the best of my ability, but I make sure to test out EACH AND EVERY PIECE of code I wrote in these assignments to make sure my code is “spitting out” what I am expecting, and to show you and the TAs what I was trying to do just in case I get something wrong (because showing work for some points is better than showing no work for 0 points, you know?)

Each student has their method, and planning out WHEN to work and HOW LONG to work on assignments is my method; I just think it is a shame that students resort to cheating when things get tough or they are too lazy to actually learn, because again, that is unfair to me as a student who dedicates time and energy to every assignment in this class.

- Former COGS 18 Student

The most important reminder: you must have written, understand, and be able to explain any code you turn in as your own.

When can you work with others in COGS 18?

  • Coding Labs

  • Assignments

Working with others is different than copying from others. It is never acceptable to just ask someone for their answers or their code.

On Coding Labs & Assignments, it is OK to ask one another questions about what you’re working on. It is OK to share screens and talk through your answers.

If you find yourself copying + pasting someone else’s code (from a friend or from the Internet)…you’re probably making a mistake.

When can you NOT work with others?

  • Exams

Exams are the only time in this course we ask you to work on material completely on your own.

Exams assess your understanding after you’ve had plenty of practice (in lecture, on coding labs, and on assignments).

It’s your time to show off what you know.

Exams are open notes and open Google.

You can search the Internet for help on concepts.

You are not allowed to ask anyone specific questions from the Exam or post the questions anywhere.

Part of your first Coding Lab will help to make this all as clear as possible!

Optional, do this if you are interested…#

Install Python on your computer#

You only need access to datahub for this course, but for working on your projects and for downloading and opening the notebooks used in class, you may want to download anaconda onto your computer, which comes complete with conda, and Jupyter notebooks.

Anaconda is an open-source distribution of Python, focused on scientific computing in Python.
The anaconda website is here.

The Anaconda Ecosystem#

  • Anaconda itself is a distribution - that is, a copy of the Python standard library, included a curated collection of external packages.

  • Conda is a package manager, allowing you to download, install, and manage other packages.

Download anaconda from here.

Notes#

  • If you are on Mac, you have a native installation of Python. This native installation of Python may be older, will not include the extra packages that you will need for this class, and is best left untouched.

    • Downloading anaconda will install a separate, independent install of Python, leaving your native install untouched.

  • Windows does not require Python natively and so it is not typically pre-installed.

# You can check which python you are using, and what version it is.
#  Once you have installed anaconda, you should see you are using Python in your anaconda folder
#  Make sure that the version you have is 3.6 (or at least 3.X)
#  Note: these are command-line functions that may not work on windows
!which python
!python --version

Web Browser#

Jupyter notebooks display in a web browser. They are not hosted on the web, everything is happening locally.

If you click on the url in the browser, you will notice it says ‘localhost’. This means it is connected to something locally, on your computer.

That local connection is to the ‘kernel’.