wai-quantum: any exercise is checked as a lesson is (engine::course::check_exercise) #645
Loading…
Reference in a new issue
No description provided.
Delete branch "wai/quantum-check-exercise"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The first step toward the job service writing a program for an intent and checking every attempt.
The change
The course's check held a program to a lesson's exercise, and only the lesson lookup tied it to the course.
engine::course::check_exercisetakes an exercise as a document in the course's own form (wai.quantum.exercise/1) and checks a program the same way: the same verdicts, constraints and words, withlessonnull.checknow looks up its lesson and calls the same function, so a lesson's check of a program that passes comes out as the same bytes as before.Why
When the service writes a program for someone's intent, each attempt needs to be held to the task the way a lesson's answer is. The check's account of what went wrong becomes the feedback for the next attempt. The course's exercise format already carries everything a task needs: what the program must do (an intent, or one per case), constraints, the job it runs as, and a starter program.
Review fixes (2026-11-06)
A review of the write loop found that this check, once it is the only gate on a pass, held vacuously where it read nothing. Fixed here:
engine::course::exercise_formholds a document to a lesson's form as far as a check reads it, andcheck_exerciserefuses what it refuses before anything runs. Refused now:{"max": 1.5},{"max": "0"},{"max": 0.0}, a bare number), and a constraint or field the course does not name (each held vacuously or was dropped);shots,seedandnoise: a non-object job panicked the check, andrepairordyadic_bitsmade the engine prove a different program from the one recorded;MOST_CASES) or 8 intents in one place (MOST_INTENTS).Q114); before, it ran without the input, and the bit-flip lesson passed with no flip at all. A case whoseintentis null takes the exercise's, and a case named with one string is shown by it.porrzby an odd multiple of π/4 counts one, and a Clifford gate counts none. Any other gate (a rotation by another angle, a Toffoli) holds to no T count, since its count is not fixed. A gate on three qubits holds to no two-qubit count. Before, the t-count lesson passed with every T written asp(pi/4).{"max": n}alone. The course says them as "at most n"; with a min, the check enforced a bound its words did not state.exercise.v1.jsonsays so ($defs/at_most), and capscasesat 16.Second review (2026-11-06)
input uint err;and never used it passed the bit-flip lesson at proof. One that branched on the classicalerrpassed the syndrome lesson.inject, names the input whose value is the qubit an error flips. The cases' programs may then differ in that one gate alone: anxon the qubit the case names, with every other gate, measurement and step the same (course::injected). So the error is in the quantum state, the program cannot read it classically, and its quantum operations must find and correct it.qubits({"max": n}), closes the last way round: an answer kept on a qubit that no error reaches.bit-flip-codeandsyndromeset both. The schema names both, and a set of cases that cannot carry an injection is refused.an_injected_error_is_corrected_from_the_qubits_and_never_read. Onba59c776eit failed for the reason it states: the declared, unused input passedbit-flip-code.Tests
an_exercise_outside_the_course_is_checked_as_a_lesson_is: a lesson's own exercise, given as a document, checks byte for byte as the lesson does; an exercise written from nothing but a distribution passes a Bell pair by proof and fails a program with no CNOT.13015f77afor the reason it states:a_malformed_exercise_is_refused_before_anything_is_checked:{"t_count": 0}was checked and passed;every_case_binds_its_inputs_and_is_held_to_the_constraints: the no-flip program passed the bit-flip lesson;a_t_count_counts_t_gates_however_they_are_written: the respelled t-count answer passed.engine::schema::(lessons, checks and hints held to their schemas) the total is 24.cargo check --no-default-features --features quantum_engineandquantum_engine,quantum_receiptpass with-D warnings.wai-quantum-docs.ymlcounts 14 and requires each by name.Changelog
A file of its own,
wai/changes/2026-11-05-quantum-any-exercise-checked-as-lesson.md, as main now takes entries.wai/CHANGELOG.mdis main's.🤖 Generated with Claude Code
The course words these bounds as "at most n" (constraint.t_count, two_qubit, estimate), and the check read a min too: {"t_count": {"min": 2}} showed the model "at most ? T and T† gates" while it failed every program with fewer than two. The reader now takes {"max": n} alone for them (engine::course::at_most), and exercise.v1.json says so ($defs/at_most), with the T count's description saying how T gates are counted. No lesson uses a min there. Found sweeping the review's family of claims the check makes that the code does not keep. Co-Authored-By: Claude Opus 5.5 <[email protected]>The second review found finding 1 closed only for undeclared inputs. A program that declared `input uint err;` and never used it passed the bit-flip lesson at proof, and one that branched on the classical err passed the syndrome lesson. A new constraint, `inject`, names the input whose value is the qubit an error flips. The cases' programs may then differ in that one gate alone, an x on the qubit the case names, every other gate, measurement and step the same (course::injected). So the error is in the quantum state, the program cannot read it classically, and what finds and corrects it is the program's quantum operations, the same in every case. A program that never applies the error, reads it elsewhere, or flips another qubit fails, saying which. A second, `qubits` ({"max": n}), closes the last way round: an answer kept on a qubit no error reaches. bit-flip-code and syndrome set both; their solutions and wrong answers keep their results. The exercise schema names both, and a case set an injection cannot be made from is refused. Test an_injected_error_is_corrected_from_the_qubits_and_never_read, failing onba59c776efor the reason it states (the declared, unused input passed bit-flip-code). Course tests 13 -> 14 in wai-quantum-docs.yml. Co-Authored-By: Claude Opus 5.5 <[email protected]>