Useful Tools.

Computational Physics - PHYS 305 (UArizona)

The science of today is the technology of tomorrow.

Edward Teller

$ whoami
nikhilgaruda

$ pwd
/Users/nikhilgaruda/UA/PHYS_305

$ date
Thu Jan 30 12:15:00 MST 2025

$ ls
README.md    bash/    git/    python/
README.md    bash/    git/    python/

Useful Tools.

We will cover some basic computational tools required for any computational research project.

README.md    bash/    git/    python/

Bash 

Bourne Again SHell

What is it?

  • It's command-line interface used to interact with your operating system.
  • It’s a powerful scripting language for automating tasks and controlling systems directly through commands.

Why Use the Terminal?

  • Speed & Efficiency - Perform complex tasks in seconds
  • Automation - Automate repetitive tasks with scripts
  • Full Control - Access advanced system features and configurations
  • Remote Access - Connect to remote machines without a graphical interface
  • Resource-Friendly - Makes it ideal low-power tasks
README.md    bash/    git/    python/

Bash 

$ pwd
/workspaces/hw1-Nikhil0504
psst... use TAB ↹ to autocomplete your commands
Print Working Directory
README.md    bash/    git/    python/

Bash 

$ pwd
/workspaces/hw1-Nikhil0504

$ ls
README.md

$ ls -a
.  ..  .git  .gitignore  README.md
psst... use TAB ↹ to autocomplete your commands
List Directory Contents
Shows hidden contents
Previous Folder
Present Folder
README.md    bash/    git/    python/

Bash 

$ pwd
/workspaces/hw1-Nikhil0504

$ ls
README.md

$ ls -a
.  ..  .git  .gitignore  README.md

$ mdkir -p src/phys305_hws
psst... use TAB ↹ to autocomplete your commands
Create a new directory
Creates multiple directories
README.md    bash/    git/    python/

Bash 

$ pwd
/workspaces/hw1-Nikhil0504

$ ls
README.md

$ ls -a
.  ..  .git  .gitignore  README.md

$ mdkir -p src/phys305_hws

$ touch pyproject.toml
psst... use TAB ↹ to autocomplete your commands
Create a new file
README.md    bash/    git/    python/

Bash 

$ pwd
/workspaces/hw1-Nikhil0504

$ ls
README.md

$ ls -a
.  ..  .git  .gitignore  README.md

$ mdkir -p src/phys305_hws

$ touch pyproject.toml

$ cd src/phys305_hws
$ touch a2.py
$ ls
a2.py
psst... use TAB ↹ to autocomplete your commands
Change directory to that path
Repeating same steps
README.md    bash/    git/    python/

Git

What is it?

  • It's a distributed version control system that helps developers manage and track changes in their code over time.
  • It allows multiple people to collaborate on a project without overwriting each other’s work.

Why Use Git?

  • Version Control: Track and revert code changes.

  • Collaboration: Work together without overwriting changes.

  • Distributed System: Local copies for offline work.

  • Backup & Redundancy: Full backups across multiple systems.

  • Remote Collaboration: Sync with team in real-time.

Github, Gitlab, Bitbucket, etc.

Git

$ git init
Initialized empty Git repository in /Users/nikhilgaruda/Desktop/testing/.git/

$ git add README
$ git status
On branch main

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   README

$ git commit -m "Add README"
[main (root-commit) 373b474] Add README
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README
 
 $ git push
Initialise a Git repo
README.md    bash/    git/    python/
Stage the changes to be committed

It can be a folder or a file.

Check the status of the repo
Main Branch
Files/Folders we added for committing in repo
Commit changes to repo
Push changes to repo
psst... use TAB ↹ to autocomplete your commands
README.md    bash/    git/    python/

Python

Virtual Environments & Packages

README.md    bash/    git/    python/

Python

$ python -m venv phys305
$ conda create -n phys305 python=3.11

Virtual Env (in-built)

Anaconda

Create the environment
README.md    bash/    git/    python/

Python

$ python -m venv phys305

$ source phys305/bin/activate

(phys305) $
$ conda create -n phys305 python=3.11

$ conda activate phys305

(phys305) $

Virtual Env (in-built)

Anaconda

Activate the environment
README.md    bash/    git/    python/

Python

$ python -m venv phys305

$ source phys305/bin/activate

(phys305) $

(phys305) $ pip install numpy
$ conda create -n phys305 python=3.11

$ conda activate phys305

(phys305) $

(phys305) $ conda install numpy

Virtual Env (in-built)

Anaconda

Installing packages
README.md    bash/    git/    python/

Python

$ python -m venv phys305

$ source phys305/bin/activate

(phys305) $

(phys305) $ pip install numpy

(phys305) $ deactivate

$
$ conda create -n phys305 python=3.11

$ conda activate phys305

(phys305) $

(phys305) $ conda install numpy

(phys305) $ deactivate

$

Virtual Env (in-built)

Anaconda

Deactivate the environment
README.md    bash/    git/    python/

Python

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
psst... use TAB ↹ to autocomplete your commands
pyproject.toml

The build backend determines how your project will specify its configuration, including metadata and input files

README.md    bash/    git/    python/

Python

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "phys305_hws"
version = "0.1"
dependencies = [
	'numpy',
  	'scipy',
  	'matplotlib',
]
requires-python = ">=3.10"
authors = [
  {name = "Nikhil Garuda", email = "nikhilgaruda@arizona.edu"},
]
description = "Package containing HWs for my Computational Physics Class"
readme = "README"
psst... use TAB ↹ to autocomplete your commands
pyproject.toml

This section will contain the basic properties of your python package and also all the dependencies.

Now, you don't need to have a separate requirements.txt!!

Just do pip install -e . instead

phys_305_useful_tools

By Nikhil Garuda

phys_305_useful_tools

  • 130