In-class Assignment 1.2¶

Week 1 Wednesday

✅ Write your group member's names here¶


Part 1: Set up a GitHub repository together¶

In the pre-class assignment, you created a directory on your JupyterHub where you initialized a repository and linked it to the remote Github class wiki repository. In doing so, you practiced some terminal commands for navigating directories, issuing git commands, and making changes to files through the command-line interface (CLI).

Today, you'll build on those skills to set up a system where you can collaborate on coding assignments with your group members.

One group member only: Go to GitHub and create a new repository for your group!¶

At the top of the page, click the plus icon and then "New Repository". This will be the repository in which the whole group will collaborate for the next three weeks. Decide on a short but memorable name for the repo. For now, ignore the configuration options section.

Note: By default, Github makes repositories public. Do not put any information in a public repository that you do not want other people to see, including private keys, personal emails, or anything you do not want linked to yourself.

Once you've created the repository, add everyone in your group as collaborators to your repo. Also, add the faculty instructor and grad TA.

Every group member: Make a local repository in your JupyterHub¶

Hint: you've done this before!

Open up the JuypterHub Terminal, and try to achieve this task using only terminal commands -- everything you need to do this is from the PCA. More detailed steps are listed below.

In a local JuypterHub directory where you want your version of your small group repo to live, create a file introducing yourself. The file should be a plaintext file (.txt) or markup file (.md).

Once you have finished, you can initialize a repository in that directory.

git init

This creates a new hidden subdirectory named .git that contains all of the necessary files to maintain a Git repository skeleton. At this point, nothing in your project is tracked. See Git Internals for more information about exactly what files are contained in the .git directory.

We should now be able to see what is going on in our newly created project.

Some of the most important commands to see what is going on in your repository are git status and git log. git status will tell you what branch you are on, the current state of every file in the project, including whether it has been added or deleted, and whether or not the changes are different from the remote repository. git log will show every commit that has been made and the local branch that it has been made on, as well as the commit hash and remote bbranch. It shows the author, the date, and a portion of the commit that has been written.

Make a change to local your repo and push it¶

Since we have already created a file, we now want to begin tracking said file and commit it to the worktree.

git add <filename>
git commit -m "write a message in quotes about adding your file"

You always want to leave at least a short, descriptive message explaining what the commit is for. The -m stands for "message", which allows you to write a short and simple line straight from the terminal. If you omit that, git will automatically open a text editor for you to write a longer commit message.

At this stage, git may prompt you to enter a username and email. The username you set here will be public, so be cognizant of what you choose if you ever start committing to public projects on github. I would suggest putting something like the first letter of your first name and your last name, or just your last name.

The user.email field will also be public. Your github account by default creates a separate noreply email for you, which is a good security practice so that your email is not scraped by bots and put on a phishing list. You can find this email by going to Settings --> Access --> Emails and copy-pasting the email shown atop your primary email. It will be in the format of

00000001+<username>@users.noreply@github.com

You likely already configured a name and email during the pre-class assignment. To change these settings, you can always edit the ~/.gitconfig file directly, or run:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

To set your account's default identity. This will set your credentials for every future repository you create.

Now we can link our local repository to github by adding a remote repository. This is where you will link your local git to the repository you created earlier.

git remote add origin git@github.com:<user>/<repository>.git

You can also get this URL from GitHub directly -- just click the green "Code" button when you are looking at a repo site, and copy the SSH URL (not the HTTPS URL).

This will add a remote to the git repository, which you can now send changes to (push) and receive changes from (pull).

You can return to this step if you ever want to do this again for another repo, or if you want to link another machine.

You can now push to the GitHub repository!

To do this, you can run

git push --set-upstream origin main

You will only need to "set your upstream" once, so that git knows where to send your changes when you type git push at a later time without a remote repo specified.

Now go to GitHub. You should see your file there. Congrats! You have pushed to your first remote repository.


Part 2: Create a group agreement¶

To guide how you want to collaborate together in class, you will discuss your collaboration goals together and write up an agreement.

Discuss these questions together, and write up notes in a separate file that you will share on your group repo. You can choose to designate one person as a notetaker, who can push their notes onto the shared repo after your discussion.

If you are up to a git challenge, you could also choose to collaborate on one document for which multiple group members can edit and commit/push changes.

Here are the discussion questions you'll need to address:

For each group member:

  • What parts of participation seem like they will be challenging for you?
  • What is a goal you can set related to collaboration or modeling that you can work towards?
  • How can your group members help support you or keep you accountable to this goal?

As a group:

  • What expectations do you have for one another to function effectively as a group?
  • How will you communicate with one another about the group project? (even if someone has to miss class unexpectedly)
  • What is the role of respect, cooperation, mutual trust, and openness in this group?
  • If group members disagree on how to approach the group project, how will that conflict be handled?

Using generative AI during group work:

  • Section 1: Share experiences? (1)
    • Each person briefly shares: (maybe document this too??)
      • How they’ve used genAI in past coursework (e.g., PH 264 or other classes) or personal projects
      • What felt helpful, confusing, or uncomfortable about using genAI?
      • What they avoid using genAI for?
  • Section 2: Potential uses of genAI? And the un/reasonable? --> What should we use it for? (2) How do we decide when to use it? (3 part 1)
    • As a group, list the possible uses of genAI in computational physics tasks. For each use, discuss what is un/reasonable, and perhaps ambiguous (cases where it depends on context, intent, etc.).
  • Section 3: Should we even use genAI? (3 part 2)
    • Do we want genAI to be part of our workflow?
    • How do we respect those preferences while still allowing others to explore genAI? (section 2?)
    • If we do use genAI, under what conditions? (e.g., only for debugging?, only for explanation, not code generation?, etc.)
    • If we choose not to use genAI:
      • What are our reasons?
      • What alternatives will rely on? (e.g., LAs, online sources, etc.)
      • How will we handle situations where someone wants to use genAI later?
  • Section 4: How will the group document the usage of generative AI? (4)
    • As a group, discuss what counts as “using genAI” (e.g., copy/paste?, brainstorming?, etc.)
    • When to disclose genAI use to each other?
    • How will the group record/document the usage of genAI? (e.g., a shared log, comments in code, etc.)

We will use/not use genAI for...

Before using genAI, we will first...

When using genAI in our work, we will disclose...


Part 3: Go through the steps of the modeling cycle¶

✅ Identify all four steps of the modeling cycle to the existing code below, adding markdown chunks with narrative text to explain them.

✅ As you go, also add comments to the code to explain most of the lines of code. You can skip lines that your already addressed earlier (for example, you don't have to explain plt.show() twice).

✅ At the very, pose new questions that you could investigate about this phenomenon.

How hot can a magnet get until it's not a magnet anymore?¶

Starting from a mean field theory equation that models the magnetization of a material based on the mean behavior of individual particles.

$$ M = \tanh \left(\frac{MnJ}{k_B T}\right) $$

M is magnetization, and T is temperature. The other values are constants: n is number of particles, J can be modeled as a material constant, k_B is Boltzmann constant.

Let's begin by looking for a graphical solution. Define x=nJ/kT at fixed J, x >> 1 corresponds to low temperature while x << 1 is high temperature

In [29]:
import numpy as np

M = np.linspace(0,1.5,1000)
In [61]:
import matplotlib.pyplot as plt

x_vals = [2.0, 1.5, 1.25, 1.0, 0.75, 0.5]

for x in x_vals:
    plt.plot(M, np.tanh(M * x), label="x = %0.2f" % x)
    
plt.plot(M, M, color="black", linestyle="--", label="M = tanh(Mx)")

plt.xlabel("M")
plt.legend()
plt.title("Mean Field Theory Solutions")
plt.show()
No description has been provided for this image

There seems to generally be a solution between 0 and 1. So let's solve...

In [48]:
def mean_field_eqn(mag, x_temp):
    return mag - np.tanh(mag * x_temp)
In [49]:
from scipy.optimize import fsolve

N = 10000

x = np.linspace(0.5, 100, N)
Mx = np.empty(N)

for i in range(N):
    sol_i = fsolve(mean_field_eqn, 1.1, args=(x[i]))
    Mx[i] = sol_i[0]
In [54]:
plt.plot(1.0 / x, Mx, linewidth=4)
plt.xlabel('Temperature T/(nJ)')
plt.ylabel('Magnetization M')
plt.ylim(-0.001,1.05);
plt.show()
No description has been provided for this image
In [ ]: