Introduction to Physics Computing MT 2013 Lecture 1 J Tseng Outline    Objectives of the computing course Some practical course details Basic concepts and pitfalls MT 2013 (I) Introduction to.

Download Report

Transcript Introduction to Physics Computing MT 2013 Lecture 1 J Tseng Outline    Objectives of the computing course Some practical course details Basic concepts and pitfalls MT 2013 (I) Introduction to.

Introduction to
Physics Computing
MT 2013
Lecture 1
J Tseng
Outline



Objectives of the computing course
Some practical course details
Basic concepts and pitfalls
MT 2013 (I)
Introduction to Physics Computing (Tseng)
2
Objectives

Learn basic computing skills





Lectures – basic ideas



Computation and numerical methods
Data processing and analysis
Modelling and simulation
Awareness of other uses of computers in physics
How to tell computers what to do
How computers work
Practical course – learn by doing


Actual programming
Actual applications
MT 2013 (I)
Introduction to Physics Computing (Tseng)
3
Computers in physics






Non-linear equations, non-analytic solutions
Data processing, pattern recognition, analysis
Modelling and simulation
Automated control
Data acquisition
Communication: e-mail, web
MT 2013 (I)
Introduction to Physics Computing (Tseng)
4
The Large Hadron Collider
CERN, Geneva
MT 2013 (I)
Introduction to Physics Computing (Tseng)
5
9 orders of magnitude
Signal vs background
All interactions
The Nobel Prize
(Not the Nobel Prize)
MT 2013 (I)
Introduction to Physics Computing (Tseng)
6
Detectors
COLLISION RATE
Charge
Time
Pattern
16 Million channels
3 Gigacell buffers

100 kHz
LEVEL-1 TRIGGER
Energy
Tracks
1 MegaByte EVENT DATA
1 Terabit/s
200 GigaByte BUFFERS
(50000 DATA CHANNELS)
500 Readout memories
EVENT BUILDER
500 Gigabit/s


~109 events per
experiment per year
1-2MB/event
Multiple processing
passes
Networks
20 TeraIPS
Gigabit/s SERVICE LAN
Grid Computing
Service
PetaByte ARCHIVE
300 TeraIPS
50 CD-ROM
6 cm
EVENT FILTER
10 PB => 18 km
40 MHz
10 miles
High-volume data processing
= 33 GB
MT 2013 (I)
Introduction to Physics Computing (Tseng)
7
Computing outside research



Animation
Financial/risk modelling
“Big Data”

Can Tesco tell you’re
pregnant before you
know?
MT 2013 (I)
Introduction to Physics Computing (Tseng)
8
Computers everywhere

No longer uncommon to
refer to a mobile
“operating system”


Android and others based on
Linux kernel
Desktop and mobile
operating systems and user
interfaces merging (?), e.g.,
Windows 8 and Ubuntu Unity
MT 2013 (I)
Introduction to Physics Computing (Tseng)
9
Computers within computers


Computer programs are also used to “emulate” other computers
 Sometimes old computers simply don’t exist anymore, but you
still want to run the programs
 Operating systems (such as Windows 98) aren’t supported
anymore, but your program can’t be upgraded
 Want to run untrusted program safely – protect against viruses
 Increase utilization of web servers
 Partition computers in a “cloud”
 Or, you’re just nuts
See http://www-jpc.physics.ox.ac.uk
for some local information and
demonstration on the topic
MT 2013 (I)
Introduction to Physics Computing (Tseng)
10
How to tell a computer what to do



Examples given can involve millions of
instructions
Built from much simpler logical elements
Basic idea: issue a sequence of instructions


You can issue this sequence by hand, one
instruction at a time
Sequences can be written and stored
 programs, functions
MT 2013 (I)
Introduction to Physics Computing (Tseng)
11
Programs for people
MT 2013 (I)
Introduction to Physics Computing (Tseng)
12
Programs for people
MT 2013 (I)
Introduction to Physics Computing (Tseng)
13
Programs for computers


Computers are not people
Computers are really, really, really stupid






Therefore programming can’t be mysterious
They have to be told everything
There is minimal cultural context
Sequence is important: what does a computer know, and
when does it know it?
“A computer does what you tell it to do, not what you
want it to do”
In general, the best relationship with computers is
not to trust them
MT 2013 (I)
Introduction to Physics Computing (Tseng)
14
Programs for computers (2)

How you might tell a robot:
function shampoo()
for j = 1:2
lather();
rinse();
end
end

Still have to tell the robot how to lather and rinse!

Build up from smaller program elements
MT 2013 (I)
Introduction to Physics Computing (Tseng)
15
Programming language

Previous example is in the style of a “high-level”
programming language




“High level” simply means there’s a good chance a properly
trained human can figure out what the instructions do
“Low level” languages are harder to figure out, e.g., the actual
numerical codes the computer uses to put voltages down wires
In either case, there is usually a strict grammar, or else the
computer will get confused
No matter high “high level” a language, it is still built on
lower-level constructs


One goal of computer science is to find out more natural ways for
humans to express what they want to fundamentally stupid
machines
We will look at one popular construct called “object-oriented
programming” later in the course
MT 2013 (I)
Introduction to Physics Computing (Tseng)
16
Programming languages
Where we used to be



Different traditions
and models, often
depending on
original application
“Every programmer
knows there is one
true programming
language. A new
one every week.”
B Hayes, “The
Semicolon Wars”,
American Scientist,
July/Aug 2006
MT 2012 (2)
Printers/graphics
web
Introduction to Physics Computing (Tseng)
17
Matlab

Originally a system for calculating with matrices


Now considerably expanded with data analysis,
visualization, symbolic math, other toolkits
Also has its own programming language


This is what we’ll use in the course
If you see a toolkit for domestic robotics,
see if it pre-defines lather() and rinse()
Web App
App
Web browser
Java App
Matlab App
Matlab
Java Virtual Machine
Operating System
MT 2013 (I)
Introduction to Physics Computing (Tseng)
18
Other “super” calculators

Octave




mostly similar syntax with Matlab
open source
command line rather than graphical user interface
Mathematica

MT 2013 (I)
Also very popular for scientific computing
Introduction to Physics Computing (Tseng)
19
Practical course details

All students are signed up to do CO01 first, using
the online Prelims Computing Course




http://www-teaching.physics.ox.ac.uk/CO-MATLAB/
This will take you through the elements of Matlab use for
calculations and programming language
Best way to learn to program is to do it
You should know when you are to show up in lab


There are 20-30 computers, so pre-allocation is intended to
make sure everyone gets time to do it
If you get behind, you can show up for extra sessions.
Check with the demonstrators on shift – pre-allocated
students get priority
MT 2013 (I)
Introduction to Physics Computing (Tseng)
20
Practical course details (2)

You can also start CO01 at home
 This will reduce the amount of time you actually have to sit in lab
 Come to lab for questions and to be marked off by a
demonstrator
 The demonstrator is not responsible for figuring out problems with
your home computer – be prepared to transfer your work to the
lab machines
 You can install Matlab on your computer



The Department has bought student licences for all undergraduates
See the Prelims Computing Course webpage for the link to download
Asking for help or getting marked in lab
 Get a demonstrator’s attention
 Don’t be surprised if you may have to wait
 Continue working as far as you can at your computer
 Demonstrators should attend largely in sequence
MT 2013 (I)
Introduction to Physics Computing (Tseng)
21
Lecture scheme
Learn by doing in the practical lab
Lectures will try to convey more general
ideas and pitfalls


Getting started with Matlab as a calculator
Simple programs
Encoding concepts




Intention is not to duplicate online course
material in lectures, but to point out areas of
common misunderstanding
MT 2013 (I)
Introduction to Physics Computing (Tseng)
22
How Matlab looks
Files
Command Window:
type commands here
What you’ve
stored
What you’ve
done
Snapshots
MT 2013 (I)
Introduction to Physics Computing (Tseng)
23
Most important Matlab commands

exit





clear



For slightly less drastic problems
This just clears out your storage without having to exit
Matlab
help


Type this in the Command Window
Press the ENTER or RETURN key
Restart if needed
This should always clear up catastrophic confusion
Type this followed by a command or function
These are also available in the menus
MT 2013 (I)
Introduction to Physics Computing (Tseng)
24
Storage: “variables”


If you want to save something for later, you put it in a
pigeonhole (often called a “variable”, but not in the same
sense as in mathematics)
Matlab pigeonholes can store





Numbers also come in different types, e.g.,




Numbers
Vectors, matrices, and arrays
Strings (arrays of codes representing characters)
“objects”: combined data and code
int32: -231 to (231-1)
float: 6 digits, 10-38 to 1038, machine epsilon ~10-7
double: 15 digits, 10-308 to 10308, machine epsilon ~10-16
Boolean type (true/false) represented a non-zero or zero
numerical value
MT 2013 (I)
Introduction to Physics Computing (Tseng)
25
Storage

Every pigeonhole has a name and a type




Unless you specify otherwise, it’s usually double
Every pigeonhole name must begin with a letter
Upper and lower case characters are different
There are “reserved words” which cannot be used
as a pigeonhole name

Matlab will usually complain if you misuse a reserved word
MT 2013 (I)
Introduction to Physics Computing (Tseng)
26
Operators

For calculations, similar to arithmetic
(3 + 4) / 2


* is multiplication and / division, rather than 
and ÷
Normal operator precedence: */ before +-:
3+4/2→5

Assignment is an operator!
MT 2013 (I)
Introduction to Physics Computing (Tseng)
c = 3 + 4 / 2;
27
Element-wise operators

Variables can store scalars or matrices




* is usual matrix multplication
May want to multiply element by element: .*
Similarly for ./ and .^
Useful when “matrices” are really data arrays
MT 2013 (I)
Introduction to Physics Computing (Tseng)
28
Relational operators

Again, similar to what you would expect







Evaluated after arithmetic operators
These operators take number types and return an integer 0
for false and 1 for true, like a boolean value
Interpretation for matrices?



> and <
>= and <= for including equality
~= for inequality
== for equality (since = is for assignment)
“M>8” applies “>8” to every element of M
Result is a matrix of booleans
If there is a possible matrix interpretation to any expression,
there’s a good chance that’s what Matlab does
MT 2013 (I)
Introduction to Physics Computing (Tseng)
29
Boolean operators


AND, OR, NOT of Boolean expressions
In Matlab, two forms:





Operators: a & b, a | b, ~a
1 or 2-argument functions: and(a,b), or(a,b), not(a)
You will run into these again in digital electronics
(electronics practical lab)
Even lower precedence than relational operators
It is good to use parentheses for clarity in spite
of well-defined operator precedence
MT 2013 (I)
Introduction to Physics Computing (Tseng)
30
Some common pitfalls



Names are case-sensitive: a vs A
Assignment vs equality: = vs ==
Trying to compare strings with ==




Conventional vs element-wise ops: * vs .*
Smallest iotas: different meanings of



A computer doesn’t know if you’ve abandoned a command, or you want to finish a
long one
Name conflicts: reserved words and old variables



.,;:
()[]{}
Line continuation: …


More than one way to compare strings
Use functions such as strcmp(), strcmpi(), strncmp(), strncmpi()
Just because you’ve forgotten doesn’t mean the computer has
One of the reasons clear is such an important command
Not an exhaustive list of pitfalls, merely a general introduction
MT 2013 (I)
Introduction to Physics Computing (Tseng)
31
Next step

Get started with CO01 at home/in college



Learn by doing
Ask for help when you get stuck – some concepts
may take a little getting used to
Next week: programs, control flow
MT 2013 (I)
Introduction to Physics Computing (Tseng)
32