๐Ÿ“ฑ Android โ†’ HPC Server

Android Phone as a
Quantum Espresso Job Server

A complete guide to turning an old Android phone into a remote DFT compute server with job submission, monitoring, and remote access.

6
CPU Cores
7.2GB
RAM
~22s
Si vc-relax
ARM64
Architecture

Table of Contents

  1. Overview & Architecture
  2. Prerequisites
  3. Step 1: SSH Server Setup
  4. Step 2: Job Queue (Redis + RQ)
  5. Step 3: Flask REST API
  6. Step 4: Compile Quantum Espresso
  7. Step 5: Full Job Submission Workflow
  8. Step 6: Auto-Start on Boot
  9. Step 7: Remote Access via Tailscale
  10. Quick Reference
1

Overview & Architecture

This guide walks through setting up a complete DFT job submission system on an Android phone using Termux. The phone acts as a compute server โ€” you submit jobs from your laptop, the phone runs them, and you download the results.

SYSTEM ARCHITECTURE
๐Ÿ’ป Laptop โ”€โ”€โ”€โ”€ HTTP / Tailscale VPN โ”€โ”€โ”€โ”€โ–บ ๐Ÿ“ฑ Phone (Flask API)
โ†“
๐Ÿ”„ Redis Queue โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ โš™๏ธ RQ Worker
โ†“
โš›๏ธ pw.x (Quantum Espresso)
๐Ÿ“ฑ
Termux
Linux environment on Android
๐Ÿ”„
Redis + RQ
Job queue & worker
๐ŸŒ
Flask
REST API server
โš›๏ธ
Quantum Espresso
DFT engine (ARM64)
๐Ÿ”’
Tailscale
Remote VPN access
๐Ÿš€
Termux:Boot
Auto-start on reboot
2

Prerequisites

Phone Requirements

  • Android 7.0+ device
  • At least 4GB RAM (6GB+ recommended)
  • At least 10GB free storage
  • Termux installed from F-Droid (not Play Store)

Install from F-Droid

Download and install these apps from f-droid.org:

  • Termux โ€” main terminal app
  • Termux:Boot โ€” for auto-start on reboot
โš ๏ธ

Important: Do not install Termux from the Play Store โ€” it is outdated. Always use the F-Droid version.

Battery Optimization (Critical)

Go to Settings โ†’ Apps โ†’ Termux โ†’ Battery โ†’ Unrestricted
Do the same for Termux:Boot. This prevents Android from killing the server.

3

Step 1: SSH Server Setup

๐Ÿ“ฑ On Phone (Termux)
# Update packages
pkg update && pkg upgrade -y

# Install SSH server
pkg install openssh -y

# Set a password
passwd

# Start SSH server
sshd
๐Ÿ’ป From Laptop
# Connect to phone (default port 8022)
ssh -p 8022 192.168.1.46
โ„น๏ธ

Find your phone's IP by running ifconfig in Termux or checking your router's connected devices.

4

Step 2: Job Queue (Redis + RQ)

๐Ÿ“ฑ On Phone (via SSH)
# Install dependencies
pkg install redis python -y
pip install flask rq

# Start Redis
redis-server --daemonize yes

# Test Redis
redis-cli ping
# Should return: PONG
# Create project directory
mkdir ~/jobserver && cd ~/jobserver

# Create tasks.py
cat > tasks.py << 'EOF'
import time, subprocess

def sleep_job(seconds):
    time.sleep(seconds)
    return f"Slept {seconds}s"

def run_script(script_path, args=None):
    cmd = ["bash", script_path] + (args or [])
    result = subprocess.run(cmd, capture_output=True, text=True)
    return {"stdout": result.stdout, "stderr": result.stderr, "code": result.returncode}

def run_qe(input_file, output_file=None):
    if output_file is None:
        output_file = input_file.replace('.in', '.out')
    pw = '/data/data/com.termux/files/home/q-e/bin/pw.x'
    result = subprocess.run(
        [pw, '-i', input_file],
        stdout=open(output_file, 'w'),
        stderr=subprocess.PIPE,
        text=True
    )
    return {
        "output_file": output_file,
        "returncode": result.returncode,
        "stderr": result.stderr
    }
EOF
5

Step 3: Flask REST API

๐Ÿ“ฑ On Phone (via SSH)
# Create server.py using Python
python3 -c "
content = '''from flask import Flask, request, jsonify, send_file
from rq import Queue
from rq.job import Job
from redis import Redis
import tasks, os

app = Flask(__name__)
conn = Redis()
q = Queue(connection=conn)
UPLOAD_DIR = \"/data/data/com.termux/files/home/qe_jobs\"
os.makedirs(UPLOAD_DIR, exist_ok=True)

@app.route(\"/upload\", methods=[\"POST\"])
def upload():
    if \"file\" not in request.files:
        return jsonify({\"error\": \"no file provided\"}), 400
    f = request.files[\"file\"]
    path = os.path.join(UPLOAD_DIR, f.filename)
    f.save(path)
    return jsonify({\"path\": path, \"message\": \"uploaded successfully\"})

@app.route(\"/submit\", methods=[\"POST\"])
def submit():
    data = request.json
    job_type = data.get(\"type\")
    if job_type == \"qe\":
        job = q.enqueue(tasks.run_qe, data[\"input\"], data.get(\"output\"), job_timeout=3600)
    elif job_type == \"sleep\":
        job = q.enqueue(tasks.sleep_job, data[\"seconds\"])
    else:
        return jsonify({\"error\": \"unknown job type\"}), 400
    return jsonify({\"job_id\": job.id, \"status\": str(job.get_status())})

@app.route(\"/status/\", methods=[\"GET\"])
def status(job_id):
    job = Job.fetch(job_id, connection=conn)
    return jsonify({\"id\": job.id, \"status\": str(job.get_status()), \"result\": job.result})

@app.route(\"/jobs\", methods=[\"GET\"])
def list_jobs():
    queued = [j.id for j in q.get_jobs()]
    return jsonify({\"queued\": queued, \"length\": len(q)})

@app.route(\"/download\", methods=[\"GET\"])
def download():
    path = request.args.get(\"path\")
    if not path:
        return jsonify({\"error\": \"no path provided\"}), 400
    try:
        return send_file(path, as_attachment=True)
    except Exception as e:
        return jsonify({\"error\": str(e)}), 404

if __name__ == \"__main__\":
    app.run(host=\"0.0.0.0\", port=5000)
'''
open('/data/data/com.termux/files/home/jobserver/server.py', 'w').write(content)
print('done')
"
# Install tmux for managing multiple processes
pkg install tmux -y
tmux new -s jobserver

# In tmux - split panes with Ctrl+B then %
# Left pane: start RQ worker
cd ~/jobserver && rq worker

# Right pane: start Flask (Ctrl+B then right arrow)
cd ~/jobserver && python server.py

API Endpoints

MethodEndpointDescription
POST/uploadUpload input file to phone
POST/submitSubmit a job to the queue
GET/status/<job_id>Check job status
GET/jobsList queued jobs
GET/download?path=...Download output file
6

Step 4: Compile Quantum Espresso

โฑ๏ธ

Compilation takes 30โ€“60 minutes. Keep the phone plugged in and make sure Termux stays active.

๐Ÿ“ฑ On Phone (via SSH)
# Install build dependencies
pkg install cmake make clang flang openblas fftw patchelf llvm -y

# Install missing library fix
pkg install libandroid-complex-math -y
ln -s /data/data/com.termux/files/usr/lib/libandroid-complex-math.so \
      /data/data/com.termux/files/usr/lib/libandroid-complex-math.a

# Create symlinks for missing tools
ln -s /data/data/com.termux/files/usr/bin/llvm-ar \
      /data/data/com.termux/files/usr/bin/ar
ln -s /data/data/com.termux/files/usr/bin/flang \
      /data/data/com.termux/files/usr/bin/gfortran

# Clone Quantum Espresso
cd ~ && git clone https://github.com/QEF/q-e.git
cd ~/q-e
# Configure with flang
./configure F77=flang FC=flang

# Fix make.inc (remove duplicate compiler entries)
grep "^MPIF90\|^F90\|^LD" make.inc
# Ensure these are all set to 'flang' with no duplicates:
# MPIF90 = flang
# F90    = flang
# LD     = flang

# Fix lapack make.inc
sed -i 's/FORTRAN  = gfortran/FORTRAN  = flang/' ~/q-e/install/make_lapack.inc
sed -i 's/OPTS     = -O3 -g/OPTS     =/' ~/q-e/install/make_lapack.inc
sed -i 's/LOADOPTS = -g/LOADOPTS =/' ~/q-e/install/make_lapack.inc
# Build pw.x with all cores
make pw -j6 2>&1 | tail -20

# Verify binary exists
ls ~/q-e/bin/pw.x
# Download Silicon pseudopotential
mkdir -p ~/pseudo ~/out ~/qe_jobs
wget https://pseudopotentials.quantum-espresso.org/upf_files/Si.pbe-n-rrkjus_psl.1.0.0.UPF \
     -P ~/pseudo/
โœ…

Test your installation: ~/q-e/bin/pw.x -i ~/si_vcrelax.in > ~/si_vcrelax.out 2>&1

7

Step 5: Full Job Submission Workflow

Save this as submit.py on your laptop:

๐Ÿ’ป On Laptop
import requests, sys, time, os

PHONE_URL = "http://100.83.65.14:5000"  # Your phone's Tailscale IP

def upload_and_submit(input_file):
    print(f"Uploading {input_file}...")
    with open(input_file, 'rb') as f:
        r = requests.post(f"{PHONE_URL}/upload", files={"file": f})
    remote_path = r.json()["path"]
    print(f"Uploaded to: {remote_path}")

    r = requests.post(f"{PHONE_URL}/submit", json={
        "type": "qe", "input": remote_path
    })
    job_id = r.json()["job_id"]
    print(f"Job ID: {job_id}")

    while True:
        r = requests.get(f"{PHONE_URL}/status/{job_id}")
        status = r.json()["status"]
        print(f"Status: {status}")
        if "FINISHED" in status:
            return job_id, r.json()["result"]["output_file"]
        elif "FAILED" in status:
            sys.exit("Job failed!")
        time.sleep(5)

def download_output(output_file):
    local_file = os.path.basename(output_file)
    r = requests.get(f"{PHONE_URL}/download", params={"path": output_file})
    open(local_file, 'wb').write(r.content)
    print(f"Saved to {local_file}")

if __name__ == "__main__":
    job_id, output = upload_and_submit(sys.argv[1])
    download_output(output)
    print("Done!")
# Usage
python3 submit.py my_calculation.in
1
Upload POST /upload โ€” sends .in file to phone's ~/qe_jobs/
2
Submit POST /submit โ€” enqueues job in Redis
3
Execute RQ worker picks up job, runs pw.x
4
Poll GET /status โ€” checks every 5s until FINISHED
5
Download GET /download โ€” retrieves output file to laptop
8

Step 6: Auto-Start on Boot

Install Termux:Boot from F-Droid, open it once, then create the boot script:

๐Ÿ“ฑ On Phone (via SSH)
mkdir -p ~/.termux/boot

cat > ~/.termux/boot/start_server.sh << 'EOF'
#!/data/data/com.termux/files/usr/bin/bash
termux-wake-lock
sleep 10
pkill -f "redis-server"
pkill -f "rq worker"
pkill -f "python server.py"
sleep 2
redis-server --daemonize yes
sleep 2
cd /data/data/com.termux/files/home/jobserver
rq worker &
sleep 2
python server.py &
EOF

chmod +x ~/.termux/boot/start_server.sh
โ„น๏ธ

The sleep 10 gives Android time to fully boot before starting services. After phone restart, the server will be available in ~15 seconds.

9

Step 7: Remote Access via Tailscale

Tailscale creates a secure VPN mesh so you can access your phone from anywhere without port forwarding.

๐Ÿ’ป On Laptop
# Install Tailscale
curl -fsSL https://tailscale.com/install.sh | sh
sudo tailscale up
# Visit the URL shown to authenticate

# Get your laptop's Tailscale IP
tailscale ip
๐Ÿ“ฑ On Phone

Install Tailscale from the Play Store and log in with the same account.

๐Ÿ’ป On Laptop โ€” Test Remote Access
# Replace with your phone's Tailscale IP (shown in Tailscale app)
curl http://100.83.65.14:5000/jobs
# Should return: {"length":0,"queued":[]}
๐ŸŽ‰

Once connected, update PHONE_URL in submit.py to your phone's Tailscale IP. You can now submit jobs from anywhere in the world!

10

Quick Reference

Key Paths on Phone

ItemPath
QE Binary~/q-e/bin/pw.x
Pseudopotentials~/pseudo/
Job inputs~/qe_jobs/
Job server~/jobserver/
Boot script~/.termux/boot/start_server.sh

Common curl Commands

# Check server status
curl http://<PHONE_IP>:5000/jobs

# Upload input file
curl -X POST http://<PHONE_IP>:5000/upload -F "[email protected]"

# Submit QE job
curl -X POST http://<PHONE_IP>:5000/submit \
  -H "Content-Type: application/json" \
  -d '{"type": "qe", "input": "/path/to/input.in"}'

# Check job status
curl http://<PHONE_IP>:5000/status/<job_id>

# Download output
curl "http://<PHONE_IP>:5000/download?path=/path/to/output.out" -o output.out

Sample Silicon vc-relax Input

&CONTROL
  calculation = 'vc-relax'
  prefix = 'silicon'
  outdir = '/data/data/com.termux/files/home/out'
  pseudo_dir = '/data/data/com.termux/files/home/pseudo'
/
&SYSTEM
  ibrav = 2
  celldm(1) = 10.2
  nat = 2
  ntyp = 1
  ecutwfc = 30.0
  ecutrho = 120.0
/
&ELECTRONS
  conv_thr = 1.0e-8
/
&IONS
  ion_dynamics = 'bfgs'
/
&CELL
  cell_dynamics = 'bfgs'
/
ATOMIC_SPECIES
  Si 28.086 Si.pbe-n-rrkjus_psl.1.0.0.UPF
ATOMIC_POSITIONS {alat}
  Si 0.00 0.00 0.00
  Si 0.25 0.25 0.25
K_POINTS {automatic}
  4 4 4 0 0 0

Completed Checklist

  • SSH server running on port 8022
  • Redis + RQ job queue configured
  • Flask REST API with upload/submit/status/download endpoints
  • Quantum Espresso compiled from source on ARM64
  • Silicon vc-relax test calculation (~22 seconds)
  • Auto-start on boot via Termux:Boot
  • Remote access from anywhere via Tailscale
  • Python submission script on laptop