# Practice 1 - Requesting the Grid certificate. Registering to *balticgrid* VO. Python warm-up.

**Date**: 13.02.2012 **Deadline**: for 1st and 2nd exercise: one day before your next practice session and for 3rd exercise: 03.03.2012

- Practical slides: PDF
- Exercise 1: Requesting a Grid certificate
- Exercise 2: Registering to
*balticgrid*VO - Exercise 3: Python warm-up

## Exercise 1. Requesting a Grid certificate

Grid Security Infrastructure (GSI) is laying on Public Key Infrastructure (PKI). It means all parties (users, recourses and services) need a certificate for authentication.

The first exercise is to **request and get a Grid certificate** from Baltic Grid Certification Authority (BGCA).

User's instructions for generating a grid certificate request can be found here, but some further comments:

- For generating the certificate request login to
**atigrid.mt.ut.ee**with your UT account. The command line:`ssh atigrid.mt.ut.ee`

- Generating certificate request:
- Don't change the DC components (just press ENTER)
- Domain Component [org]:
- Domain Component [balticgrid]:

- Domain Institution should be for you
**ut.ee**- Domain of the Institution (domain.zz) []:
**ut.ee**

- Domain of the Institution (domain.zz) []:
- Common Name must be your
**full name**with replaced diacritical marks look here for additional information- Common Name (John Smith) []:
**Firstname Lastname**

- Common Name (John Smith) []:

- Don't change the DC components (just press ENTER)
- Fill the form with your information and upload your certificate request file (usercert_request.pem).
- In RA's list choose
**Hardi Teder or Pelle Jakovits**(the one who will check your ID). - You also have to click the link in the confirmation email.

- In RA's list choose

If you missed the first practice then you have two options:

- Sign your request file with Estonian ID-card and send the signed file with your personal information to Hardi Teder.
- Arrange face-to-face meeting with Hardi Teder or Pelle Jakovits.

## Exercise 2. Registering to *balticgrid* VO

The second exercise is **to get you registered in balticgrid Virtual Organization** (VO).

If you have received your Grid certificate signed by BGCA, you should:

- Import it to your web browser: Estonian Grid guide
- Fill the registration form for balticgrid VO.
- Do not forget to click the confirmation link in email you will get from VOMS service.

**VO registration should be done at least one day before your next practical** session because it takes time to distribute the information.

## Exercising Python

The goal of the second exercise is to give students the opportunity to examine and adapt to the Python programming language.

**Python's documentation and courses**

Python documentation: http://www.python.org/doc

Tutorial for Beginners: A thorough tutorial - all the important topics covered.(recommended for Python newbies) http://docs.python.org/tut/

Python Library Reference: http://docs.python.org/lib/lib.html

## Exercise 3: Approximating Pi with Monte Carlo Integration

Write a Python function that finds the approximate value of π (pi) by using numbers from a pseudo-random sequence.

The number π is a mathematical constant that is the ratio of a circle's circumference to its diameter (approximately 3.14159).

Given that the area of a circle is

π**r*^{2}

where *r* is the radius of the circle and

(2*r*)^{2}

is the area of a square, then we can find π from the relation

π**r*^{2}/(2*r*)^{2} = π**r*^{2}/4*r*^{2} = π/4.

Now, the function *sqrt*(1-x^{2}) describes a halfcircle, if we can find the definite integral over the domain {0 .. 1}

we will find the following area (marked in red)

Analogously this area's relation to a 1 by 1 square is also equal to π/4.

The Monte Carlo method for finding the integral involves sampling the function with values of x taken from a pseudo-random, preferably uniformly distributed, number sequence. The problem with calculating π in this way is that accurately calculating each following digit will have to be about 10 times as many samples as to calculate the preceding digit.

2.1. Write a function that takes an integer input parameter n and prints out the approximate value of π, found by feeding n random values of x to *sqrt*(1-x^{2}).

- Find the value of the Integral
- Find the average value of the function in the given domain {0 .. 1} using the Monte Carlo method.
- Find the size of the area by multiplying the previous result with the size of the domain
- In this case, size (which is
**length**in**1D**space) of the domain is**1**, so can be skipped.

- In this case, size (which is

- Find
**π**based on the value of the integral.

2.2. Test your program with different values of n. How long does the program take to execute to get an accurate value of π up to 5 digits after the comma?

**Deliverables:** Python source files of your program, and a .txt file with a brief description of the experiments and their results.

Read also the Grid practical exercise solution format page to learn how to finalize and upload your solution.