Fix #56: derive hasMeasurement() from the gates instead of a flag - #110
Closed
corgab wants to merge 1 commit into
Closed
Fix #56: derive hasMeasurement() from the gates instead of a flag#110corgab wants to merge 1 commit into
corgab wants to merge 1 commit into
Conversation
…a flag CircuitBuilder kept a private $hasMeasurement flag that push() had to set, while gateCount() and depth() derived the same fact by scanning $gates. The flag is gone: validate() asks a new public hasMeasurement() that scans the gates like its siblings, so there is no hand-maintained invariant left and callers can ask the question too. Closes #56
Owner
Author
|
Chiusa in vista della migrazione all'architettura 100% PHP. Mantenere il flag O(1) è la scelta migliore per le performance con circuiti nativi di grandi dimensioni. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CircuitBuilderkept a private$hasMeasurementflag thatpush()had to set, whilegateCount()anddepth()derived the same fact by scanning$gates. The flag is gone: the question is answered from the gates, the way its siblings already do.Plan
push().hasMeasurement(): boolthat scans$gatesfor a measurement (a plain loop, sincearray_any()is PHP 8.4 and the package supports 8.3), and havevalidate()call it.append()ever changed: a measurement dropped from an appended fragment does not count.Changes
src/Circuit/CircuitBuilder.php:$hasMeasurementremoved;hasMeasurement()added next tovalidate(), with a docblock explaining why it is derived;push()only validates and appends.README.md:hasMeasurement()listed withgateCount()anddepth()in the inspection example.tests/Unit/Circuit/CircuitBuilderTest.php: false beforemeasure(), true after; a fragment's measurement does not leak in throughappend(), andrun()still refuses such a circuit.Tests
vendor/bin/pint --testpasses.vendor/bin/pest --compact: 793 tests, 1 skipped (791 before: +2).Closes #56
Generated by Claude Code