Giter Site home page Giter Site logo

data-science-methods's Introduction

DSE-512 Playground

GitHub license

Table of Contents

About

A playground repo for the DSE-512 course.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

You need to have a machine with Python > 3.6 and any Bash based shell (e.g. zsh) installed.

$ python3.8 -V
Python 3.8.5

$ echo $SHELL
/usr/bin/zsh

You will also need to install MPI in your system. Ref for Ubuntu

Installing, Testing, Building

All the installation steps are being handled by the Makefile. The server=local flag basically specifies that you want to use conda instead of venv, and it can be changed easily in the lines #25-28. local is also the default flag, so you can omit it.

If you don't want to go through the detailed setup steps but finish the installation and run the tests quickly, execute the following command:

$ make install server=local

If you executed the previous command, you can skip through to the Running locally section.

Check the available make commands

$ make help
-----------------------------------------------------------------------------------------------------------
                                              DISPLAYING HELP                                              
-----------------------------------------------------------------------------------------------------------
Use make <make recipe> [server=<prod|circleci|local>] to specify the server
Prod, and local are using conda env, circleci uses virtualenv. Default: local

make help
       Display this message
make install [server=<prod|circleci|local>]
       Call clean delete_conda_env create_conda_env setup run_tests
make clean [server=<prod|circleci|local>]
       Delete all './build ./dist ./*.pyc ./*.tgz ./*.egg-info' files
make delete_env [server=<prod|circleci|local>]
       Delete the current conda env or virtualenv
make create_env [server=<prod|circleci|local>]
       Create a new conda env or virtualenv for the specified python version
make setup [server=<prod|circleci|local>]
       Call setup.py install
make run_tests [server=<prod|circleci|local>]
       Run all the tests from the specified folder
-----------------------------------------------------------------------------------------------------------

Clean any previous builds

$ make clean delete_env server=local

Create a new virtual environment

For creating a conda virtual environment run:

$ make create_env server=local 

Build Locally (and install requirements)

To build the project locally using the setup.py install command (which also installs the requirements), execute the following command:

$ make setup server=local

Run the tests

The tests are located in the tests folder. To run all of them, execute the following command:

$ make run_tests server=local

Running the code locally

In order to run the code, you will only need to change the yml file if you need to, and either run its file directly or invoke its console script.

If you don't need to change yml file, skip to Execution Options.

Modifying the Configuration

There is an already configured yml file under confs/template_conf.yml with the following structure:

tag: template
example_db:
  - config:
      hostname: example.host.name
      username: my_name
      password: !ENV ${PASS}
      db_name: my_db1
      port: 3306
    type: mysql

The !ENV flag indicates that you are passing an environmental value to this attribute. You can change the values/environmental var names as you wish. If a yaml variable name is changed/added/deleted, the corresponding changes should be reflected on the yml_schema.json too which validates it.

Set the required environment variables

In order to run the main.py you will need to set the environmental variables you are using in your configuration yml file. Example:

$ export PASS=my_password

The best way to do that, is to create a .env file (example), and source it before running the code.

Execution Options

First, make sure you are in the correct virtual environment:

$ conda activate dse512_playground

$ which python
/home/drkostas/anaconda3/envs/dse512_playground/bin/python

DSE-playground Main

Now, in order to run the code you can either call the main.py directly, or invoke the playground_main console script.

$ python playground/main.py --help
usage: main.py -c CONFIG_FILE [-m {run_mode_1,run_mode_2,run_mode_3}] [-l LOG] [-d] [-h]

A template for python projects.

Required Arguments:
  -c CONFIG_FILE, --config-file CONFIG_FILE
                        The configuration yml file

Optional Arguments:
  -m {run_mode_1,run_mode_2,run_mode_3}, --run-mode {run_mode_1,run_mode_2,run_mode_3}
                        Description of the run modes
  -l LOG, --log LOG     Name of the output log file
  -d, --debug           Enables the debug log messages
  -h, --help            Show this help message and exit


# Or

$ playground_main --help
usage: main.py -c CONFIG_FILE [-m {run_mode_1,run_mode_2,run_mode_3}] [-l LOG] [-d] [-h]

A template for python projects.

Required Arguments:
  -c CONFIG_FILE, --config-file CONFIG_FILE
                        The configuration yml file

Optional Arguments:
  -m {run_mode_1,run_mode_2,run_mode_3}, --run-mode {run_mode_1,run_mode_2,run_mode_3}
                        Description of the run modes
  -l LOG, --log LOG     Name of the output log file
  -d, --debug           Enables the debug log messages
  -h, --help            Show this help message and exit

DSE-playground CLI

There is also a cli.py which you can also invoke it by its console script too (cli).

$ cli --help
Usage: cli [OPTIONS] COMMAND [ARGS]...

Options:
  --install-completion [bash|zsh|fish|powershell|pwsh]
                                  Install completion for the specified shell.
  --show-completion [bash|zsh|fish|powershell|pwsh]
                                  Show completion for the specified shell, to
                                  copy it or customize the installation.

  --help                          Show this message and exit.

Commands:
  bye
  hello

Deployment

The deployment is being done to Heroku. For more information you can check the setup guide.

Make sure you check the defined Procfile (reference) and that you set the above-mentioned environmental variables (reference) .

Continuous Integration

$ which python /home/drkostas/anaconda3/envs/DSE512-playground/bin/python (DSE512-playground)


### Execution Options <a name = "execution_options"></a>

Depending on the file you want to run, you'll need to follow the corresponding instructions. To view them, just run:

```bash
$ python <your file name>.py --help
usage: <your file name>.py -m {run_mode_1,run_mode_2,run_mode_3} -c CONFIG_FILE [-l LOG]
               [-d] [-h]

<Your python file\'s description.

required arguments:
  -m {run_mode_1,run_mode_2,run_mode_3}, --run-mode {run_mode_1,run_mode_2,run_mode_3}
                        Description of the run modes
  -c CONFIG_FILE, --config-file CONFIG_FILE
                        The configuration yml file
  -l LOG, --log LOG     Name of the output log file

optional arguments:
  -d, --debug           enables the debug log messages

To run it following the instructions.

data-science-methods's People

Contributors

drkostas avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

data-science-methods's Issues

Assignment05 - Q2

(25 points) Pulling containers

Containers can also be persisted to disk by “pulling”. Run the following command to pull the docker image into a singularity image file, and verify that you can shell into it.
singularity build pydatacpu.sif docker://dceoy/pydata:dnn-cpu

Assignment05 - Q1

(25 points) Ephemeral containers

We will launch a shell in an “ephemeral container” that is downloaded on demand and deleted when we are done. This is useful when trying out an image whenyou are unsure whether you will use it long-term or not. First, from an ISAAC login node, run the
following commands and note the output:
grep PRETTY_NAME /etc/os-release
ls /

Next, Run the following command do drop into an ephemeral singularity container. This may take a few
minutes.
singularity shell docker://dceoy/pydata:dnn-cpu

Re-run the first to commands from inside this shell and note the differences. You are inside a container which
has applied an overlay to the true filesystem. Press Ctrl-d to exit

Assignment05 - Q0

(0 points) Setup

We will be downloading containers, which will exhaust your home directory disk
quota. So first, create a new cache directory for singularity, and export the following environment
variable in your shell session.

export SINGULARITY_CACHEDIR=/lustre/haven/proj/UTK0150/$USER/singularity_cache
mkdir $SINGULARITY_CACHEDIR

Now, within this terminal any singularity commands will use the given directory to store the large image files
we will download, and you should not run out of disk space.

Assignment05 - Q4

(25 points) Run kmeans_vectorized.py in the container

Now, use the skills you developed in the first few problems to run your kmeans_vectorized.py script from previous assignments. Verify that the output matches what we saw in Assignment 01.

Assignment02

  • (25 points) Clone the kmeans repository into your own area at /lustre/haven/proj/UTK0150/$USER.
  • (25 points) Write a job script that will use a single node and a single process per node (so only one process total). Ensure the job runs on a compute node, and run the non-distributed kmeans (kmeans_vectorized.py). Make a note of the output directory and commit the job script to your cloned repo.
  • (25 points) Write another job script to run the distributed kmeans script on two compute nodes using 20 processes, using the same iris data we've been looking at and submit the job, noting the output directory. This job should finish in a very short amount of time so requesting a walltime of 5 minutes will help you get through the queue quicker. Don't forget that you must launch your processes with mpirun inside the script...
  • (25 points) Modify the script to use the TCGA data in the /lustre/haven/proj/UTK0150/data directory (see README for refresher on how to load the data). Run another job on ISAAC using 20 processes and time how long the script takes to run, using 10 clusters. Make a note of the time it takes. Also run with a single process and one node and verify that both jobs output identical cluster assignments and centroids by saving the outputs of each job, loading them once complete and verifying that they match. (hint: successs at this requires identical initialization).
  • Submit a message here with the following information:
    • path to your code on ISAAC.
    • paths and brief description of relevant output log directories for ISAAC jobs that succeeded (please don't make us sort through your main output directory ourselves and sort through failed job IDs).
    • Timings for k-means on Iris and TCGA data, with single process vs twenty. Do you achieve a 20x speedup in each case?

Your assignment will not be graded unless you submit it here on Canvas; no exceptions.

Assignment01

  • Problem 1
  • Problem 2
  • Problem 3
  • Add detailed comments
  • Deploy and test on ISAAC
  • Do the additional programming challenges

Assignment04 - Q2

Question 2

After training the model for 30 epochs for each of the p number of ranks in the problem
one, let’s compare both our models’ accuracy and their total runtime for each run.
Create two plots:

a. A line plot showing the epoch accuracy for each of the runs
b. A second line plot that shows the total runtime by the number of processes used

What is the effect of training time as we increase the number of processes available?
How does this line up with your expectations of the scalability laws that we discussed?
Which scalability law is most applicable in this case? How is our model accuracy
affected by the increase in the number of processes running? Present your figures and
answers to these questions in either a short document or a Jupyter notebook in your
repository.

Assignment05 - Extra

More exercises (0 points)

There you have it. A singularity container that has pandas, numpy, and other machine learning packages already installed, without having to manage a conda environment. Note that mpi4py is missing, and if you’d like to install it, you would need to extend this container. However, it is difficult to do so, since you must build new containers on another computer that you have root access on, like an Ubuntu virtual machine. That is not part of this assignment, but is the next step in understanding and
using Singularity, so if you are looking for more to learn, try modifying this container on a local machine (using the singularity bootstrap command and editing a Singularity file), then copying it back onto ISAAC to verify that it ran.

Assignment04 - Q1

Question 1

Let’s write a data-parallel convolutional net to train on the MNIST dataset. Our goal
is to see how data-parallel training affects two things: our model’s accuracy, and its
runtime. Due to some limitations on Isaac, we are going to train this model using a
single node, but we will increase the number of processes per node to see how things
scale. Use the number of processes p ∈ {1, 2, 4, 8} and train the model for 30 epochs
each time. We want to keep track of two things:

a. Our training accuracy at every epoch
b. The total time it takes the model to train

Note: I recommend saving your training accuracy at every epoch as a numpy
array. You should have a numpy array for each run where p number of processes
were used. In the next step, we will plot these accuracy curves for each of the runs
to compare how our model accuracy changes as we vary the number of processors
(and the effective batch size as a result).

Steps:

  • Create a class that will include all the assignment operations
  • Load train and test MNIST
  • Pick CNN architecture and create Model Class
  • Create Training Part
  • Create Testing Part
  • Store the run statistics
  • Create a Data-Parallel version
  • Test for different number of processes
  • Create .pbs script and run it on ISAAC

Assignment05 - Q3

(25 points) Bind mounting directories

By default, singularity containers mount /home/$USER, /tmp, and $PWD, meaning you can see them inside your container. Let’s also mount your user home directory and print its contents from within the container. If you named your user directory something other than your username, you will need to make that edit to this command.
singularity exec --bind /lustre/haven/proj/UTK0150/$USER:/myproj pydatacpu.sif ls -l /myproj

Assignment03

For this assignment, you will extend the code we created in class, located at /lustre/haven/proj/UTK0150/jhinkl13/kmeans.
The submission you return to us should be a brief report formatted in HTML, DOCX, or PDF.
For the report that you submit, you do not need to overly format it; you can simply list your responses
to each of the problems below.

Please do the following using number of clusters -k 4, using the TCGA dataset:

  • (25 points) Starting from the kmeans repository developed in class, which you extended in the last
    two assignments, refactor the kmeans.py to contain the following subfunctions: compute_distances(),
    expectation_step(), maximization_step(), called at the appropriate places inside the kmeans()
    function. Ensure that the program still runs. Do this for kmeans_vectorized.py as well. In your
    report, indicate you’ve completed problem 1 and provide the path to your code on ISAAC (or github if
    you choose to use it).
  • (25 points) Profile your newly-refactored kmeans.py and report the time spent in each of the
    three new functions both in seconds and as a percentage of the total runtime. Do the same
    for kmeans_vectorized.py. Recall that kmeans_vectorized.py attempted to speed up the
    compute_distances() portion
    . Use Amdahl’s Law to compute the theoretical maximum speedup
    possible by optimizing and parallelizing the compute_distances(). What percentage of that speedup
    have we actually obtained
    by vectorization with numpy?
  • (25 points) Visualize an icicle plot of the profiling output for kmeans.py. You may use Snake- Vis or Viztracer along with cprofiler, as Todd demonstrated in Lecture 15. Do the same for
    kmeans_vectorized.py
    . You may include these as screenshots in your report; please rescale the figures
    to ensure that we can see the main function names in these plots.
  • (25 points) Using the profiling output from Problem 2, determine the maximum speedup you could
    obtain by optimizing the expectation_step() and maximization_step()
    (note that you may need
    to refactor further to measure the runtime of the main kmeans loop). In a new file, kmeans_numba.py,
    use the @numba.jit decorator
    (install and import numba in your code), re-profiling your code, and
    compare your runtime to the ideal speedup given by applying Amdahl’s Law. Report the new profiled
    runtimes for these three functions and the total runtime using Numba in your report.
  • Full run for the tcga dataset
  • Measure times & Amdahl's law, create report, gather results, screenshots and submit.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.