<jupyter_start><jupyter_text>Running CARLA simulatorThis tutorial shows how to run and visualize CARLA on colab.              Run in Google Colab                View source on GitHub    --------- Introduction[Carla](https://github.com/carla-simulator/carla) is an open-source simulator for autonomous driving research.Since it is hardware demanding, it could be useful for students to run it on colab.--- AcknowledgementsThanks to *Tomohiro*  for developing the code that allows remote access to colab.Check out his [page](https://internet-of-tomohiro.netlify.app/google_colab/vnc.en.html) and [GitHub](https://github.com/demotomohiro/remocolab).--- UpdateNgrok doesn't work anymore with Google Colab (see [this issue](https://github.com/demotomohiro/remocolab/issues/79)). The tutorial has been updated to use Argo tunnel instead.---  Requirements*   ~~[Ngrok](https://ngrok.com/) account (you don't need to buy premium plans).~~*   [Install cloudflared](https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation) on your PC.*   TurboVNC Viewer. [Download here](https://sourceforge.net/projects/turbovnc/). (RealVNC and Microsoft Remote Desktop __don't__ work).*   Ssh client (already present in all recent os).  Change the runtimeIn colab: click "Runtime" in the top bar -> "Change runtime type" -> change hardware accelerator to GPU.  Installation & setup of remote access 1.   Run the snippet below2.   ~~It will ask for your ngrok authtoken.~~  *   ~~login to ngrok -> from the left menu: Authentication>Your Authroken -> copy~~  *   ~~Enter it~~3. ~~Select ngrok region (the region closest to you should be the fastest)~~4. Wait the end of the process  * It sets up OpenSSH server, VirtualGL and TurboVNC.  * Then, access passwords are shown<jupyter_code>!pip install git+https://github.com/demotomohiro/remocolab.git
import remocolab
remocolab.setupVNC()<jupyter_output><empty_output><jupyter_text>Connect TurboVNC1. Open a ssh connection to colab (It is necessary to secure VNC connection)  * Execute the ssh command showed above  * Use the "colab password" displayed above2. Run TurboVNC Viewer  * The connection address is `localhost:1`  * Use the "VNC password" displayed above if everything worked properly, you will see a screen.  Download CARLAIf you need another [version](https://github.com/carla-simulator/carla/blob/master/Docs/download.md) of CARLA, change the link below. You must choose a Linux version.<jupyter_code>! sudo -u colab wget -O /home/colab/CARLA.tar.gz https://carla-releases.s3.eu-west-3.amazonaws.com/Linux/CARLA_0.9.10.tar.gz<jupyter_output><empty_output><jupyter_text>Extract the zip<jupyter_code>! sudo -u colab mkdir /home/colab/carla
! sudo -u colab tar -xf /home/colab/CARLA.tar.gz -C /home/colab/carla<jupyter_output><empty_output><jupyter_text>Setup PythonAPIThe PythonAPI in the zip doesn't work with the current Colab Python version. If you change the Carla version, if you install another Python version, or if Google updates Colab, then you may not need to execute the following commands (or you may need to find another egg file accordingly).<jupyter_code>! sudo -u colab rm -rf /home/colab/carla/PythonAPI/carla/dist/*.egg
! sudo -u colab wget https://github.com/MichaelBosello/carla-colab/raw/master/carla-0.9.10-py3.6-linux-x86_64.egg -P /home/colab/carla/PythonAPI/carla/dist/<jupyter_output><empty_output><jupyter_text>Run CARLA<jupyter_code>! sudo -u colab DISPLAY=:1 vglrun /home/colab/carla/CarlaUE4.sh<jupyter_output><empty_output><jupyter_text>Run client**You can run the client on colab or on your remote pc**--- Client on colabRun the following commands in a terminal on the remote desktop Install requirement1. `sudo pip3 install pygame`  * The password for colab user is shown above Run the 'manual control' example2. `cd /home/colab/carla/PythonAPI/examples`3. `python3 manual_control.py`--- Client on your pcPerform the following steps in your pc Install requirements1. [install Carla](https://carla.readthedocs.io/en/latest/start_quickstart/a-debian-carla-installation) (use the same version of the server)2. `pip3 install pygame` Port forwardingYou have to forward two ports in addition to the one used for VNCCopy the ssh command used for the VNC connection and run it with the port changed (change 5901 which is the VNC port). You have to run it two times (in two additional terminals) with those two ports: 2000 and 2001.**For example (note that you have to change YOUR_ISTANCE_PORT to the port specified in your command):**`ssh -o UserKnownHostsFile=/dev/null -o VisualHostKey=yes -p YOUR_ISTANCE_PORT -L 2000:localhost:2000 <EMAIL>.eu.ngrok.io``ssh -o UserKnownHostsFile=/dev/null -o VisualHostKey=yes -p YOUR_ISTANCE_PORT -L 2001:localhost:2001 <EMAIL>.eu.ngrok.io` Run the 'manual control' example1. `cd /opt/carla-simulator/PythonAPI/examples`2. `python3 manual_control.py` --------- Extra Display smooth animationOpen TurboVNC Viewer options and change "Encoding method" to "Tight + Medium-Quality JPEG" or "Tight + Low-Quality JPEG(WAN)". Some noises could appear but it will look smoother.--- Tips Keeping the virtual machine aliveYou may want to use [this Chrome extension](https://chrome.google.com/webstore/detail/colab-alive/eookkckfbbgnhdgcbfbicoahejkdoele). How to transfer codeOptions:* Develop on your pc and use git to trasfer the code* Develop on your pc and mount your Google Drive from colab (see snippet below)* Install a code editor in the remote desktop (remember to save your code often on drive) TrainingSave the checkpoints of your model on your Google Drive (see snippet below)<jupyter_code>from google.colab import drive
drive.mount('/content/drive')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09676855895196507, 'fraction_numerical': 0.011528384279475983, 'mean_word_length': 4.748995983935743, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 32, 'https://': 13, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '306842', 'license': 'Apache-2.0', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1713, 'n_words': 631, 'path': 'carla-simulator.ipynb', 'repo_name': 'MichaelBosello/carla-colab', 'size': '5733'}