Skip to content

Fix #56: derive hasMeasurement() from the gates instead of a flag - #110

Closed
corgab wants to merge 1 commit into
mainfrom
fix/56-derive-has-measurement
Closed

Fix #56: derive hasMeasurement() from the gates instead of a flag#110
corgab wants to merge 1 commit into
mainfrom
fix/56-derive-has-measurement

Conversation

@corgab

@corgab corgab commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Summary

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: the question is answered from the gates, the way its siblings already do.

Plan

  1. Remove the field and its assignment in push().
  2. Add a public hasMeasurement(): bool that scans $gates for a measurement (a plain loop, since array_any() is PHP 8.4 and the package supports 8.3), and have validate() call it.
  3. Pin the behaviour with tests, including the case the flag would have got wrong if append() ever changed: a measurement dropped from an appended fragment does not count.

Changes

  • src/Circuit/CircuitBuilder.php: $hasMeasurement removed; hasMeasurement() added next to validate(), with a docblock explaining why it is derived; push() only validates and appends.
  • README.md: hasMeasurement() listed with gateCount() and depth() in the inspection example.
  • tests/Unit/Circuit/CircuitBuilderTest.php: false before measure(), true after; a fragment's measurement does not leak in through append(), and run() still refuses such a circuit.

Tests

  • vendor/bin/pint --test passes.
  • vendor/bin/pest --compact: 793 tests, 1 skipped (791 before: +2).

Closes #56


Generated by Claude Code

…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
@corgab

corgab commented Sep 10, 2026

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[maintainability] CircuitBuilder::$hasMeasurement duplicates information already derivable from $gates

1 participant