pulsesim

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package pulsesim simulates pulse programs via statevector evolution.

The simulator models single-qubit drives using the rotating-frame Hamiltonian H = Omega(t)/2 * (cos(phi)*X + sin(phi)*Y), where Omega is the complex waveform envelope and phi is the accumulated frame phase. Each waveform sample produces an analytical 2x2 unitary applied via the same stride-based kernel used in github.com/splch/goqu/sim/statevector.

Sim.Evolve processes all instructions without measuring. Sim.Run evolves the state and samples measurement counts. Sim.StateVector returns the current amplitudes for inspection.

Package pulsesim simulates pulse programs on a statevector.

The simulator models single-qubit drive Hamiltonians in the rotating frame:

H = Omega(t)/2 * (cos(phi)*X + sin(phi)*Y)

where Omega is the waveform envelope and phi is the frame phase. Each time step produces an analytical unitary (no ODE integration required).

Two-qubit interactions are supported via functional options:

  • WithCoupling enables static ZZ coupling between qubit pairs
  • WithCRFrames declares cross-resonance drive frames for 2Q entangling gates

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CRFrameMap

type CRFrameMap map[string][2]int

CRFrameMap associates cross-resonance frame names with [control, target] qubit pairs. When a Play instruction uses a CR frame, the simulator applies a 2Q cross-resonance Hamiltonian instead of a 1Q drive.

type Coupling

type Coupling struct {
	ZZ float64 // static ZZ coupling strength in rad/s
}

Coupling describes the interaction between a pair of qubits.

type CouplingMap

type CouplingMap map[[2]int]Coupling

CouplingMap maps ordered qubit pairs to their coupling parameters. Use [orderedPair] to normalize pair ordering.

type FrameMap

type FrameMap map[string]int

FrameMap associates pulse frame names with qubit indices.

type Option

type Option func(*Sim)

Option configures a pulse simulator.

func WithCRFrames

func WithCRFrames(cr CRFrameMap) Option

WithCRFrames declares which frames are cross-resonance drives.

func WithCoupling

func WithCoupling(cm CouplingMap) Option

WithCoupling sets the static qubit-qubit coupling map.

type Sim

type Sim struct {
	// contains filtered or unexported fields
}

Sim simulates pulse programs via full statevector evolution.

func New

func New(numQubits int, fm FrameMap, opts ...Option) *Sim

New creates a pulse simulator initialized to |0...0>. Optional Option values configure two-qubit coupling and CR frames.

func (*Sim) Evolve

func (s *Sim) Evolve(prog *pulse.Program) error

Evolve applies all pulse instructions, resetting the state to |0...0> first.

Example
package main

import (
	"fmt"
	"math"

	"github.com/splch/goqu/pulse"
	"github.com/splch/goqu/pulse/waveform"
	"github.com/splch/goqu/sim/pulsesim"
)

func main() {
	port := pulse.MustPort("d0", 1e-9)
	frame := pulse.MustFrame("q0_drive", port, 0, 0)

	// Constant waveform calibrated for a pi rotation.
	T := 100e-9
	amp := math.Pi / T
	wf := waveform.MustConstant(complex(amp, 0), T)

	prog := pulse.NewProgram("pi-pulse",
		[]pulse.Port{port},
		[]pulse.Frame{frame},
		[]pulse.Instruction{pulse.Play{Frame: frame, Waveform: wf}},
		nil,
	)

	sim := pulsesim.New(1, pulsesim.FrameMap{"q0_drive": 0})
	if err := sim.Evolve(prog); err != nil {
		panic(err)
	}

	sv := sim.StateVector()
	for i, a := range sv {
		p := real(a)*real(a) + imag(a)*imag(a)
		fmt.Printf("|%d> probability: %.1f\n", i, p)
	}
}
Output:
|0> probability: 0.0
|1> probability: 1.0

func (*Sim) Run

func (s *Sim) Run(prog *pulse.Program, shots int) (map[string]int, error)

Run evolves the state and samples measurement counts.

func (*Sim) StateVector

func (s *Sim) StateVector() []complex128

StateVector returns a copy of the current statevector.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL