{
 "nbformat": 4,
 "nbformat_minor": 5,
 "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"name": "python"}},
 "cells": [
  {"cell_type": "markdown", "id": "intro", "metadata": {}, "source": ["# QuantumPad · Real compute lab\n", "Run this notebook in Colab or a Python environment with PyTorch. CPU works by default; use Runtime → Change runtime type for a GPU if your account has capacity. This notebook measures actual hardware. It does not rent resources, configure billing, or guarantee a free GPU.\n", "Cloud runtimes are managed in the hosting provider's console. Results are workload-specific, not peak vendor performance."]},
  {"cell_type": "code", "id": "detect", "metadata": {}, "execution_count": null, "outputs": [], "source": ["import torch, time, json, hashlib\n", "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n", "print('Actual execution device:', torch.cuda.get_device_name(0) if device.type == 'cuda' else 'CPU')\n", "print('PyTorch:', torch.__version__)\n", "torch.manual_seed(42)\n"]},
  {"cell_type": "code", "id": "compute", "metadata": {}, "execution_count": null, "outputs": [], "source": ["n = 1024\n", "a = torch.rand(n, n, device=device)\n", "b = torch.rand(n, n, device=device)\n", "_ = a @ b  # Warm-up\n", "if device.type == 'cuda': torch.cuda.synchronize()\n", "started = time.perf_counter()\n", "output = a @ b\n", "if device.type == 'cuda': torch.cuda.synchronize()\n", "elapsed = time.perf_counter() - started\n", "reference = (a[0].double() * b[:, 0].double()).sum().item()\n", "relative_error = abs(output[0,0].item() - reference) / max(1, abs(reference))\n", "assert relative_error < 0.001, 'Output verification failed'\n", "result = {'device': str(device), 'matrix_size': n, 'elapsed_ms': elapsed * 1000, 'measured_gflops': 2*n**3 / elapsed / 1e9, 'sample_relative_error': relative_error, 'output_sha256': hashlib.sha256(output.cpu().numpy().tobytes()).hexdigest()}\n", "print(json.dumps(result, indent=2))\n", "with open('exaflop-result.json', 'w') as file: json.dump(result, file, indent=2)\n"]},
  {"cell_type": "markdown", "id": "next", "metadata": {}, "source": ["Return to [QuantumPad](https://exaflop.vercel.app/build) to compare cloud compute. Download exaflop-result.json from the notebook file browser. Stop/disconnect your runtime in the provider console when done."]}
 ]
}
