Skip to content
Agentmart
Submit a tool

gala-performance

Optimize Gala program performance — gate count, circuit depth, gradient cost, compilation time

Skill by gala-pl

IndexedApache-2.0★ 1
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/gala-pl-gala-performance

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Optimize Gala program performance — gate count, circuit depth, gradient cost, compilation time

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/gala-performance

Tools it pre-approves 10

From allowed-tools in SKILL.md: the agent may use these without asking you each time.

  • Bash(cargo
  • run
  • --bin
  • gala
  • *)
  • Read
  • Write
  • Edit
  • Glob
  • Grep

What's inside

Skill name
gala-performance
Description
Optimize Gala program performance — gate count, circuit depth, gradient cost, compilation time
License
Apache-2.0
Allowed tools
Bash(cargo, run, --bin, gala, *), Read, Write, Edit, Glob, Grep
Instructions
220 lines in SKILL.md · view on GitHub

Before installing

  • Pre-approves some shell commands

Files (1)

  • SKILL.md

SKILL.md (first lines)

## Task

$ARGUMENTS

## Overview

Performance in Gala has multiple dimensions: **circuit quality** (gates/depth), **gradient cost** (device submissions), **simulation speed**, and **compile time**.

## Circuit Optimization (gala-opt)

### Automatic Passes
```bash
# See optimized GIR
gala build src/main.gala --emit gir-opt

# Compare gate counts
gala build src/main.gala --emit gir  # Before
gala build src/main.gala --emit gir-opt  # After
```

### Key Optimizations
| Pass | Effect |
|------|--------|
| `AdjacentCancellation` | `H;H` → `I`, `X;X` → `I`, `CX(a,b);CX(a,b)` → `I` |
| `RotationMerge` | `RX(a);RX(b)` → `RX(a+b)` |
| `SingleQubitFusion` | `U1;U2;U3` → single `Unitary` |
| `TwoQubitCancellation` | Adjacent inverse pairs |
| `AncillaScheduling` | Reorder to minimize live ancillae |
| `ConstantFolding` | Classical: `2+3` → `5` |
| `DeadCodeElimination` | Remove unused pure computations |
| `InlineSmallPure` | Inline small `pure` functions |

### Manual Optimization Tips

**1. Fuse rotations yourself when possible:**
```gala
// Instead of:
rx(q, a); ry(q, b); rz(q, c)
// Use single unitary if available, or let optimizer fuse
```

**2. Minimize ancilla scope:**
```gala
// Good: ancilla allocated late, dropped early
fn good() {
    let a = qubit()
    let b = qubit()
    cx(a, b)
    b  // ancilla dropped here → auto-uncomputed
}

// Avoid: ancilla lives longer than needed
fn bad() {
    let anc = qubit()  // Lives through entire function
    // ... many ops ...
    drop(anc)  // Late drop = more qubits simultaneously
}
```

**3. Use `Qubits<N>` for register operations:**
```gala
// Efficient: single loop over register
for i in 0..N { h(qs[i]) }

// Less efficient: individual qubits
let q0 = qubit(); let q1 = qubit(); ...
```

## Gradient Cost Optimization

### Parameter-Shift Batching (Automatic)
```gala
// Before optimization: 2N submissions for N params
// After: 2 submissions (all +π/2, all -π/2)

let dθ = grad(f, wrt: θ)  // Runtime handles batching
```

### Check Gradient Cost
```bash
gala run src/vqa.gala --bench-grad
```

Output:
```
Gradient benchmark:
  Parameters: 24
  Submissions (unbatched): 48
  Submissions (batched): 2
  Speedup: 24x
  Wall time: 2.3s (vs 55s unbatched)
```

### Reduce Gradient Cost
1. **Fewer parameters** — smaller ansatz, parameter sharing
2. **SPSA optimizer** — 2 evals/step vs 2N for gradient descent
3. **Analytic gradients where possible** — some gates have known gradients
4. **Shot allocation** — more shots for sensitive params, fewer for others

```gala
// SPSA: only 2 circuit evaluations per step
let opt = spsa_optimizer(lr: 0.01, c: 0.1)
θ = opt.step(θ, loss_fn)  // No explicit grad needed!
```

## Compilation Performance

### Incremental Compilation
```bash
# First build (cold)
gala build src/main.gala

# Edit one file, rebuild (incremental — uses salsa)
gala build src/main.gala  # Much faster
```

### Frontend-Only Check (No LLVM/QuEST)
```bash
# Fast type-check without backend compilation

From gala-pl/gala, Apache-2.0.

More from gala-pl/gala

Signals

Stars
1
Forks
0
Open issues
0
Last commit (this folder)
Oct 23, 2026 (5 days ago)

From GitHub (fetched Oct 24, 2026).

Details

License
Apache-2.0
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from gala-pl

Cite this page

gala-performance skill. Agent Mart. https://agentmart.dev/skills/gala-pl-gala-performance (last updated 2026-10-24)