###### tags: `tutorials`,`for-joe` # Start programming in python_old ## Setup a conda environment This section needs to be followed only once. After setting up your conda environment follow the next section. 1. Connect to the cluster with `ssh`,i.e.: ``` ssh your_username@secure.hpcc.ucr.edu ``` 2. You need to laod `miniconda3` package: ``` module load miniconda3 ``` 3. Creat a conda environment, type this: ``` conda create -n myenv ``` Now, you can activate the environment : ``` conda activate myenv ``` Then you will be able to instll some usefull python packages : ``` conda install -n myenv numpy ``` ## Open a jupyter lab: 1. Now we request some computational resources on the cluster. Go to the `bigdata` directory: ``` cd bigdata ``` 2. Then submit a job by typing : ``` sbatch submit_jupyter.sh ``` Wait for your job to be accepted. You can checl your job's sttus by : ``` squeue -u joezen ``` If the `Time` in the output is non-zero it means your job is started: ``` JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON) 2813947 short jupyter- mqezl001 R 00:51 1 r05 ``` 3. Now open the output file of your job (instead of `2813947` put your `JOBID` from the table above): ``` vim jupyter-notebook-2813947.log ``` In that file you see an instruction similar to this : ``` MacOS or linux terminal command to create your ssh tunnel: ssh -NL 9562:r05:9562 mqezl001@secure.hpcc.ucr.edu ``` Copy the entire second line. 4. Open a new terminal tab (do not close the current one). Paste the line you just copied. You will be asked for password probably. 5. Go back to the terminal tab you had opened prevoiusly. Open the last link there with your browser, it looks like this (the details should be different): ``` http://127.0.0.1:9050/lab?token=b84a25adc00b3c6f0829e606b2b98cce186d21f5e12883e3 ``` Now you should see something like this: ![](https://i.imgur.com/ULsHhQE.png) Congratulations, you just set up your jupyter lab! Before diving inro the details of how to use this jupyter lab. Few important points: 1. Your job is valid only for 2 hours and after that it gets automatically killed by the cluster, so your connection will be lost too. If this happens, you need to follow all steps [here](https://hackmd.io/h_cI3cX5Tpye3MXP5UbL1Q#Submit-an-interactive-job-on-cluster) again. 2. Whenever you no longer need your session, you have to cancel the job manually. It is simple, ssh to the cluster again, i.e. ``` ssh joezen@secure.hpcc.ucr.edu ``` After connection to the server, type : ``` scancel -u joezen ``` Then your job is canceled. ## Run python codes in Jupyter lab: