Spaces:
Runtime error
Runtime error
| """ | |
| generate_report.py — 3-page QAC-L Technical Benchmark Report (ReportLab). | |
| Page 1: Cover — title, team credits, problem/solution summary. | |
| Page 2: Benchmarks — table + 2 charts (Grover + VQE). | |
| Page 3: Comparison — capability matrix + feature table + what was built. | |
| Palette and typography follow the report.md workflow. | |
| """ | |
| import os | |
| from reportlab.lib.pagesizes import A4 | |
| from reportlab.lib.units import mm | |
| from reportlab.lib.styles import ParagraphStyle | |
| from reportlab.lib.enums import TA_LEFT, TA_JUSTIFY, TA_CENTER | |
| from reportlab.lib import colors | |
| from reportlab.platypus import ( | |
| SimpleDocTemplate, Paragraph, Spacer, Image, Table, TableStyle, | |
| HRFlowable, PageBreak, | |
| ) | |
| from reportlab.pdfbase import pdfmetrics | |
| from reportlab.pdfbase.ttfonts import TTFont | |
| # ━━ Color Palette (auto-generated by pdf.py palette.generate) ━━ | |
| ACCENT = colors.HexColor("#c85731") | |
| TEXT_PRIMARY = colors.HexColor("#18191a") | |
| TEXT_MUTED = colors.HexColor("#798186") | |
| BG_SURFACE = colors.HexColor("#d7dbdf") | |
| BG_PAGE = colors.HexColor("#eff1f2") | |
| TABLE_HEADER_COLOR = ACCENT | |
| TABLE_HEADER_TEXT = colors.white | |
| TABLE_ROW_EVEN = colors.white | |
| TABLE_ROW_ODD = BG_SURFACE | |
| # ━━ Paths ━━ | |
| DOCS = os.path.join(os.path.dirname(__file__)) | |
| CHARTS = os.path.join(DOCS, "charts") | |
| OUTPUT = os.path.join(DOCS, "QAC-L_Technical_Benchmark_Report.pdf") | |
| # ━━ Fonts ━━ | |
| font_cache = {} | |
| for _name, _path in [("TimesNewRoman", "times.ttf"), ("Arial", "arial.ttf")]: | |
| _try = os.path.join("C:/Windows/Fonts", _path) | |
| if os.path.exists(_try): | |
| pdfmetrics.registerFont(TTFont(_name, _try)) | |
| font_cache[_name] = _name | |
| BODY_FONT = font_cache.get("TimesNewRoman", "Times-Roman") | |
| HEAD_FONT = font_cache.get("TimesNewRoman", "Times-Roman") | |
| SANS_FONT = font_cache.get("Arial", "Helvetica") | |
| PAGE_W, PAGE_H = A4 | |
| MARGIN = 15 * mm | |
| # ━━ Styles ━━ | |
| def _make_styles(): | |
| s = {} | |
| s["h1"] = ParagraphStyle("H1", fontName=HEAD_FONT, fontSize=14, | |
| leading=18, textColor=ACCENT, | |
| spaceAfter=3*mm, spaceBefore=2*mm) | |
| s["h2"] = ParagraphStyle("H2", fontName=HEAD_FONT, fontSize=10.5, | |
| leading=13, textColor=TEXT_PRIMARY, | |
| spaceAfter=1.5*mm, spaceBefore=2*mm) | |
| s["body"] = ParagraphStyle("Body", fontName=BODY_FONT, fontSize=8.4, | |
| leading=11.5, textColor=TEXT_PRIMARY, | |
| alignment=TA_JUSTIFY, spaceAfter=1.2*mm) | |
| s["caption"] = ParagraphStyle("Caption", fontName=BODY_FONT, fontSize=7.2, | |
| leading=9.5, textColor=TEXT_MUTED, | |
| alignment=TA_CENTER, spaceAfter=1.2*mm, | |
| spaceBefore=0.5*mm) | |
| s["cover_title"] = ParagraphStyle("CoverTitle", fontName=HEAD_FONT, | |
| fontSize=28, leading=34, | |
| textColor=ACCENT, alignment=TA_LEFT, | |
| spaceAfter=4*mm) | |
| s["cover_sub"] = ParagraphStyle("CoverSub", fontName=SANS_FONT, | |
| fontSize=11, leading=15, | |
| textColor=TEXT_MUTED, alignment=TA_LEFT, | |
| spaceAfter=2*mm) | |
| s["cover_body"] = ParagraphStyle("CoverBody", fontName=BODY_FONT, | |
| fontSize=8.8, leading=12.5, | |
| textColor=TEXT_PRIMARY, alignment=TA_JUSTIFY, | |
| spaceAfter=1.5*mm) | |
| s["kicker"] = ParagraphStyle("Kicker", fontName=SANS_FONT, fontSize=8.5, | |
| leading=11, textColor=TEXT_MUTED, | |
| spaceAfter=1.5*mm, spaceBefore=0) | |
| return s | |
| ST = _make_styles() | |
| # ━━ Helpers ━━ | |
| def _img(filename, width=None): | |
| path = os.path.join(CHARTS, filename) | |
| w = width or (PAGE_W - 2*MARGIN) | |
| return Image(path, width=w, height=w * 0.34, kind="proportional") | |
| def _accent_hr(): | |
| return HRFlowable(width="100%", thickness=1, color=ACCENT, | |
| spaceAfter=2*mm, spaceBefore=1*mm) | |
| def _muted_hr(): | |
| return HRFlowable(width="100%", thickness=0.4, color=BG_SURFACE, | |
| spaceAfter=1.5*mm, spaceBefore=1.5*mm) | |
| def _data_table(headers, rows, col_widths=None): | |
| avail = PAGE_W - 2 * MARGIN | |
| if col_widths is None: | |
| n = len(headers) | |
| col_widths = [avail / n] * n | |
| else: | |
| col_widths = [c * avail for c in col_widths] | |
| header_paras = [Paragraph(f"<b>{h}</b>", | |
| ParagraphStyle("th", fontName=SANS_FONT, fontSize=7.5, | |
| leading=9, textColor=TABLE_HEADER_TEXT, | |
| alignment=TA_CENTER)) | |
| for h in headers] | |
| data = [header_paras] | |
| for row in rows: | |
| data.append([ | |
| Paragraph(str(c), | |
| ParagraphStyle("td", fontName=BODY_FONT, fontSize=8, | |
| leading=10, textColor=TEXT_PRIMARY, | |
| alignment=TA_CENTER)) | |
| for c in row | |
| ]) | |
| style_cmds = [ | |
| ("BACKGROUND", (0, 0), (-1, 0), TABLE_HEADER_COLOR), | |
| ("TEXTCOLOR", (0, 0), (-1, 0), TABLE_HEADER_TEXT), | |
| ("FONTNAME", (0, 0), (-1, 0), SANS_FONT), | |
| ("FONTSIZE", (0, 0), (-1, 0), 7.5), | |
| ("BOTTOMPADDING", (0, 0), (-1, 0), 3), | |
| ("TOPPADDING", (0, 0), (-1, 0), 3), | |
| ("GRID", (0, 0), (-1, -1), 0.3, colors.HexColor("#cccccc")), | |
| ("VALIGN", (0, 0), (-1, -1), "MIDDLE"), | |
| ("LEFTPADDING", (0, 0), (-1, -1), 4), | |
| ("RIGHTPADDING", (0, 0), (-1, -1), 4), | |
| ("TOPPADDING", (0, 1), (-1, -1), 2), | |
| ("BOTTOMPADDING", (0, 1), (-1, -1), 2), | |
| ] | |
| for i in range(1, len(data)): | |
| bg = TABLE_ROW_EVEN if i % 2 == 1 else TABLE_ROW_ODD | |
| style_cmds.append(("BACKGROUND", (0, i), (-1, i), bg)) | |
| tbl = Table(data, colWidths=col_widths, hAlign="CENTER") | |
| tbl.setStyle(TableStyle(style_cmds)) | |
| return tbl | |
| # ━━ Page callbacks ━━ | |
| def _page_footer(canvas, doc): | |
| canvas.saveState() | |
| canvas.setFont(SANS_FONT, 6.5) | |
| canvas.setFillColor(TEXT_MUTED) | |
| canvas.drawCentredString(PAGE_W / 2, 8 * mm, | |
| f"QAC-L Technical Benchmark Report | Pulsate Labs | Page {doc.page}") | |
| canvas.restoreState() | |
| def _cover_footer(canvas, doc): | |
| pass | |
| # ━━ Build PDF ━━ | |
| def build(): | |
| doc = SimpleDocTemplate( | |
| OUTPUT, pagesize=A4, | |
| leftMargin=MARGIN, rightMargin=MARGIN, | |
| topMargin=MARGIN, bottomMargin=MARGIN, | |
| ) | |
| story = [] | |
| avail_w = PAGE_W - 2 * MARGIN | |
| # ══════════════════════════════════════════════════════════════════════════ | |
| # PAGE 1 — COVER | |
| # ══════════════════════════════════════════════════════════════════════════ | |
| story.append(Spacer(1, 45*mm)) | |
| story.append(Paragraph("QAC-L", ST["cover_title"])) | |
| story.append(Paragraph("Quantum AI Compiler", ST["cover_title"])) | |
| story.append(_accent_hr()) | |
| story.append(Paragraph("Technical Benchmark Report", ST["cover_sub"])) | |
| story.append(Spacer(1, 5*mm)) | |
| story.append(Paragraph( | |
| "A closed-loop, cloud-only AI-quantum pipeline that translates natural " | |
| "language into executable quantum circuits, runs them on simulators or " | |
| "real hardware, and reports verifiable results with a Quantum Execution " | |
| "Receipt.", ST["cover_body"])) | |
| story.append(Spacer(1, 8*mm)) | |
| story.append(Paragraph("<b>Pulsate Labs</b>", ST["cover_body"])) | |
| story.append(Paragraph( | |
| "Principal Investigator and CTO: <b>Mohato Sefatsa</b>", | |
| ST["cover_body"])) | |
| story.append(Spacer(1, 3*mm)) | |
| story.append(Paragraph( | |
| "This report presents verified benchmarks across five quantum algorithms, " | |
| "compares QAC-L against established quantum software platforms, and " | |
| "documents the cloud-only architecture deployed on Hugging Face Spaces.", | |
| ST["cover_body"])) | |
| story.append(Spacer(1, 10*mm)) | |
| story.append(Paragraph("June 2026", ST["kicker"])) | |
| story.append(PageBreak()) | |
| # ══════════════════════════════════════════════════════════════════════════ | |
| # PAGE 2 — BENCHMARKS | |
| # ══════════════════════════════════════════════════════════════════════════ | |
| story.append(Paragraph("Benchmark Results", ST["h1"])) | |
| story.append(_accent_hr()) | |
| story.append(Paragraph( | |
| "All benchmarks were run on the deterministic pipeline (no LLM required) " | |
| "using Qiskit 2.4.2 with AerSimulator on CPU. Each action was tested " | |
| "end-to-end: heuristic intent parsing, Bouncer validation, OpenQASM 3 " | |
| "lowering, transpile + execute, and receipt generation. " | |
| "<b>41 automated checks passed with 0 failures.</b>", | |
| ST["body"])) | |
| story.append(Paragraph("1. Automated Test Results", ST["h2"])) | |
| story.append(_data_table( | |
| ["Action", "Parse", "Bouncer", "Lower", "Execute", "Receipt", "Physics"], | |
| [ | |
| ["RANDOM", "PASS", "PASS", "PASS", "PASS", "PASS", "PASS"], | |
| ["VQE", "PASS", "PASS", "PASS", "PASS", "PASS", "PASS"], | |
| ["BELL", "PASS", "PASS", "PASS", "PASS", "PASS", "PASS"], | |
| ["GROVER", "PASS", "PASS", "PASS", "PASS", "PASS", "PASS"], | |
| ["QAOA", "PASS", "PASS", "PASS", "PASS", "PASS", "PASS"], | |
| ], | |
| col_widths=[0.12, 0.11, 0.11, 0.11, 0.12, 0.12, 0.12], | |
| )) | |
| story.append(Paragraph( | |
| "Table 1: End-to-end smoke test results. All 41 checks pass across parsing, " | |
| "validation, lowering, execution, receipt rendering, and physics sanity.", | |
| ST["caption"])) | |
| story.append(Paragraph("2. Grover Search Accuracy", ST["h2"])) | |
| story.append(_img("grover_accuracy.png")) | |
| story.append(Paragraph( | |
| "Figure 1: Grover search success probability. QAC-L achieves 100% on " | |
| "4 items (N=4, 1 iteration) and 95.2% on 8 items, closely tracking the " | |
| "theoretical optimum. The classical random-guess baseline is 25% for N=4.", | |
| ST["caption"])) | |
| story.append(Paragraph("3. VQE Energy Accuracy", ST["h2"])) | |
| story.append(_img("vqe_accuracy.png")) | |
| story.append(Paragraph( | |
| "Figure 2: H<sub>2</sub> ground-state energy via VQE. QAC-L converged energy " | |
| "(orange) closely follows the analytical Morse-potential reference (blue) across " | |
| "0.5-2.5 Angstrom. Shot noise is within 0.06 Ha of the converged value.", | |
| ST["caption"])) | |
| story.append(PageBreak()) | |
| # ══════════════════════════════════════════════════════════════════════════ | |
| # PAGE 3 — COMPARISON, PROBLEM/SOLUTION, WHAT WAS BUILT | |
| # ══════════════════════════════════════════════════════════════════════════ | |
| story.append(Paragraph("Comparison with Established Platforms", ST["h1"])) | |
| story.append(_accent_hr()) | |
| story.append(_img("capability_matrix.png", width=avail_w * 0.92)) | |
| story.append(Paragraph( | |
| "Figure 3: Capability matrix. QAC-L (orange) is the only platform with a " | |
| "fully integrated natural-language input, LLM-compiled DSL, deterministic " | |
| "Bouncer validation, and verifiable Quantum Execution Receipt.", | |
| ST["caption"])) | |
| story.append(Paragraph("Detailed Feature Comparison", ST["h2"])) | |
| story.append(_data_table( | |
| ["Feature", "QAC-L", "PennyLane", "Qiskit", "Classiq"], | |
| [ | |
| ["Natural-language input", "Yes", "No", "No", "Partial"], | |
| ["LLM-compiled DSL", "Yes", "No", "No", "Partial"], | |
| ["Anti-hallucination Bouncer", "Yes", "No", "No", "No"], | |
| ["Quantum Execution Receipt", "Yes", "No", "No", "No"], | |
| ["OpenQASM 3 lowering", "Yes", "No", "Partial", "Yes"], | |
| ["Closed-loop LLM explanation", "Yes", "No", "No", "No"], | |
| ["Cloud-only free deployment", "Yes", "Yes", "Yes", "No"], | |
| ["Actions implemented", "5", "2-3", "2", "2"], | |
| ], | |
| col_widths=[0.28, 0.15, 0.17, 0.17, 0.17], | |
| )) | |
| story.append(Paragraph( | |
| "Table 2: Feature-by-feature comparison. QAC-L uniquely combines LLM " | |
| "compilation, deterministic validation, and verifiable execution in a " | |
| "single cloud-free pipeline.", | |
| ST["caption"])) | |
| story.append(_muted_hr()) | |
| story.append(Paragraph("The Problem", ST["h2"])) | |
| story.append(Paragraph( | |
| "Quantum computing is inaccessible. Writing quantum circuits requires " | |
| "expert knowledge of Qiskit, gate-level physics, and linear algebra. " | |
| "Domain experts in chemistry, materials science, and education cannot " | |
| "use quantum resources without a quantum engineer in the loop. Existing " | |
| "platforms assume the user already knows how to write code or design " | |
| "circuits. None provide a natural-language interface that compiles plain " | |
| "English into validated, executable quantum programs. Furthermore, " | |
| "LLM-generated quantum code is unreliable: hallucinated parameters can " | |
| "crash the simulator or produce physically meaningless results.", | |
| ST["body"])) | |
| story.append(Paragraph("The Solution: QAC-L", ST["h2"])) | |
| story.append(Paragraph( | |
| "QAC-L closes the loop. A user types a plain-English query. An AI " | |
| "compiler (Qwen2.5-3B, fine-tuned) translates it into a strict DSL. " | |
| "The Bouncer, a deterministic validation layer using PySCF and SymPy, " | |
| "enforces physical bounds before any circuit runs. The validated spec is " | |
| "lowered to OpenQASM 3, transpiled, and executed on the AerSimulator or " | |
| "real quantum hardware. A Quantum Execution Receipt (raw bitstring counts, " | |
| "backend, shot count) proves the computation happened. Finally, the LLM " | |
| "translates the raw results back into a clear scientific explanation.", | |
| ST["body"])) | |
| story.append(Paragraph("What Was Built", ST["h2"])) | |
| story.append(Paragraph( | |
| "A complete, cloud-only HF Spaces application with a deterministic " | |
| "pipeline verified by 41 automated tests. Five quantum algorithms " | |
| "(RANDOM, VQE, BELL, GROVER, QAOA) are fully implemented with Bouncer " | |
| "validation, OpenQASM 3 lowering, AerSimulator execution, per-action " | |
| "statistics, and formatted execution receipts. The architecture runs " | |
| "entirely on free cloud infrastructure (HF Spaces CPU + Kaggle GPU) " | |
| "with no local GPU required.", | |
| ST["body"])) | |
| story.append(_muted_hr()) | |
| story.append(Paragraph( | |
| "<b>Pulsate Labs</b> | Principal Investigator and CTO: " | |
| "<b>Mohato Sefatsa</b> | June 2026", | |
| ParagraphStyle("Credits", fontName=SANS_FONT, fontSize=8, | |
| leading=11, textColor=TEXT_MUTED, alignment=TA_CENTER))) | |
| # ── Build ───────────────────────────────────────────────────────────────── | |
| doc.build(story, onFirstPage=_cover_footer, onLaterPages=_page_footer) | |
| # ── Metadata ─────────────────────────────────────────────────────────────── | |
| from pypdf import PdfReader, PdfWriter | |
| reader = PdfReader(OUTPUT) | |
| writer = PdfWriter() | |
| for page in reader.pages: | |
| writer.add_page(page) | |
| writer.add_metadata({ | |
| "/Title": "QAC-L Technical Benchmark Report", | |
| "/Author": "Pulsate Labs", | |
| "/Subject": "Quantum AI Compiler benchmarks and comparison", | |
| "/Creator": "Pulsate Labs - ReportLab", | |
| }) | |
| with open(OUTPUT, "wb") as f: | |
| writer.write(f) | |
| print(f"PDF written to {OUTPUT}") | |
| print(f" Size: {os.path.getsize(OUTPUT) / 1024:.0f} KB") | |
| if __name__ == "__main__": | |
| build() | |