Documentation
¶
Overview ¶
Package sweep provides parameter sweep types for evaluating variational quantum circuits across ranges of parameter values.
A Sweep resolves to a list of parameter binding maps. Primitive sweeps (Linspace, Points, Single) cover a single parameter or fixed bindings. Combinators (Product, Zip) compose sweeps into higher-dimensional spaces.
RunSim and RunDensitySim execute a parameterized circuit across all sweep points in parallel using statevector or density matrix simulation.
theta := sweep.Linspace{Key: "theta", Start: 0, Stop: math.Pi, Count: 10}
results, err := sweep.RunSim(ctx, circuit, 1024, theta)
Package sweep provides parameter sweep types for variational quantum circuits.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Linspace ¶
Linspace sweeps a single parameter over evenly-spaced values from Start to Stop (inclusive).
Example ¶
package main
import (
"fmt"
"github.com/splch/goqu/sweep"
)
func main() {
l := sweep.Linspace{Key: "theta", Start: 0, Stop: 1, Count: 3}
fmt.Println("Len:", l.Len())
for _, m := range l.Resolve() {
fmt.Printf("theta=%.1f\n", m["theta"])
}
}
Output: Len: 3 theta=0.0 theta=0.5 theta=1.0
type PointResult ¶
PointResult holds the outcome for a single sweep point.
func RunDensitySim ¶
func RunDensitySim(ctx context.Context, c *ir.Circuit, shots int, sw Sweep, nm *noise.NoiseModel) ([]PointResult, error)
RunDensitySim executes a parameterized circuit across all sweep points using density matrix simulation with an optional noise model. Results are returned in sweep order.
func RunSim ¶
RunSim executes a parameterized circuit across all sweep points using statevector simulation. Each point gets a fresh simulator instance. Results are returned in sweep order.
Example ¶
package main
import (
"context"
"fmt"
"math"
"github.com/splch/goqu/circuit/builder"
"github.com/splch/goqu/circuit/param"
"github.com/splch/goqu/sweep"
)
func main() {
theta := param.New("theta")
c, err := builder.New("ry", 1).
SymRY(theta.Expr(), 0).
MeasureAll().
Build()
if err != nil {
panic(err)
}
sw := sweep.Linspace{Key: "theta", Start: 0, Stop: math.Pi, Count: 3}
results, err := sweep.RunSim(context.Background(), c, 1000, sw)
if err != nil {
panic(err)
}
for _, r := range results {
ones := r.Counts["1"]
fmt.Printf("theta=%.2f: P(1)≈%.1f\n", r.Bindings["theta"], float64(ones)/1000)
}
}
Output: theta=0.00: P(1)≈0.0 theta=1.57: P(1)≈0.5 theta=3.14: P(1)≈1.0
type Points ¶
type Points struct {
// contains filtered or unexported fields
}
Points holds explicit values for a single parameter.
type Sweep ¶
type Sweep interface {
// Len returns the number of parameter points in the sweep.
Len() int
// Params returns the parameter names covered by this sweep.
Params() []string
// Resolve expands the sweep into concrete binding maps.
Resolve() []map[string]float64
}
Sweep defines a set of parameter bindings to evaluate a circuit over.
func Product ¶
Product returns a sweep that is the Cartesian product of the given sweeps. If any inner sweep has length 0, the result is empty.
Example ¶
package main
import (
"fmt"
"github.com/splch/goqu/sweep"
)
func main() {
x := sweep.NewPoints("x", []float64{1, 2})
y := sweep.NewPoints("y", []float64{10, 20})
p := sweep.Product(x, y)
fmt.Println("Len:", p.Len())
for _, m := range p.Resolve() {
fmt.Printf("x=%.0f y=%.0f\n", m["x"], m["y"])
}
}
Output: Len: 4 x=1 y=10 x=1 y=20 x=2 y=10 x=2 y=20