Parameterised circuits and gradients (for VQE and QAOA)

Open
#10 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python, rust

Research direction

Start by reading the circuit instruction and matrix construction code, then trace how gate fusion and expectation evaluation work; the issue does not name specific files or tests. Compare adjoint differentiation and parameter-shift behavior against the requested examples, including the special rules for crz and u. Done means parameter rebinding avoids Python re-recording and gradients are available for the stated observables.

Written by the indexing model from the issue text.

Description

enhancement
What you want to do

expectation() already gives VQE/QAOA energies, but an optimiser loop has to rebuild the whole
circuit for every parameter set and estimate gradients by finite differences. Those are slow and
inaccurate, especially on the 32-bit GPU.

Implementation notes
  • Store the parameter index in the instruction and build the matrix at run time. Gate fusion has to
    happen after the parameters are bound.
  • Adjoint differentiation is the efficient default: one forward pass plus one backward pass,
    holding about three state vectors, for all parameters at once.
  • Parameter-shift as an alternative that works with shots. The two-term rule (±π/2) is valid for
    rx, ry, rz, p and cp. crz has generator eigenvalues {0, ±½} and needs the four-term rule, and
    u should be differentiated through its three angles separately.
  • Rebinding parameters must not re-record the circuit from Python.
What it could look like
theta = qsengine.Parameter("theta")
qc = qsengine.QuantumCircuit(2)
qc.ry(0, theta)
qc.cx(0, 1)

qc.expectation("ZZ", params={"theta": 0.4})
qc.gradient(["ZZ", "XX"], coeffs=[1.0, 0.5], params={"theta": 0.4})   # -> {"theta": dE/dtheta}
Contributing
  • I would like to open a pull request for this (see CONTRIBUTING.md).
Dominant language
Rust
Stars
1
Forks
0
Avg merge
12m
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from kaiwave/qsengine

All issues in kaiwave/qsengine

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.