Parameterised circuits and gradients (for VQE and QAOA)
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
- Domain
- backend-api-design, machine-learning
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
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
ushould 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
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from kaiwave/qsengine
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 55/100
All issues in kaiwave/qsengine
Similar issues
-
bug order-flow studies ui
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
userFRM/egui-charts#2417 ·
Maintainers usually reply within 1 day
-
In a plain-text message, Font, Font Size, Font Color and Text Highlight Color stay livePossibly taken @ragelfundionctrumnar claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
UCS-Care-Group/mailcraft#862 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
smoltcp-rs/smoltcp#1243 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day