Skip to content

Add CCZ and CCX gate support#150

Open
glasses666 wants to merge 1 commit into
QuEraComputing:mainfrom
glasses666:codex/bounty-113
Open

Add CCZ and CCX gate support#150
glasses666 wants to merge 1 commit into
QuEraComputing:mainfrom
glasses666:codex/bounty-113

Conversation

@glasses666
Copy link
Copy Markdown

Closes #113.

Summary

  • Add CCZ and CCX/Toffoli support by expanding both program-text shorthand and Circuit.append() calls into the existing Clifford+T instruction set.
  • Use the 7-T CCZ decomposition discussed in the issue, with CCX derived by H-conjugating the target.
  • Add matrix truth-table coverage for CCZ and CCX, plus shorthand-vs-append coverage.
  • Update the README and docs quick-start supported-instruction lists.

Scope note

Visualization support is left out intentionally, matching the issue discussion that SVG visualization can be deferred.

Validation

  • PYTHONPATH=src uv run pytest -q -> 1087 passed in 46.24s
  • PYTHONPATH=src uv run pytest test/unit/test_circuit.py -q -> 192 passed in 1.22s
  • PYTHONPATH=src uv run pytest test/integration/test_gate_unitaries.py -q -> 117 passed in 2.27s
  • PYTHONPATH=src uv run ruff check src/tsim/utils/program_text.py src/tsim/circuit.py test/unit/test_circuit.py -> All checks passed!
  • PYTHONPATH=src uv run black --check src/tsim/utils/program_text.py src/tsim/circuit.py test/unit/test_circuit.py -> 3 files would be left unchanged
  • PYTHONPATH=src uv run pyright src/tsim/circuit.py src/tsim/utils/program_text.py test/unit/test_circuit.py -> 0 errors, 0 warnings, 0 informations

Note: in my local checkout, bare uv run pytest did not put src/ on sys.path, so I used PYTHONPATH=src for the validation commands above.

Issue QuEraComputing#113 asks for native CCZ and CCX/Toffoli support without taking on visualization. The implementation keeps the simulator path simple by expanding both shorthand and append API usage into the existing Clifford+T instruction set, using the collaborator-approved 7-T CCZ decomposition and deriving CCX by H-conjugating the target.

Constraint: Stim does not parse CCZ or CCX instructions directly

Constraint: Visualization support is explicitly out of scope for the bounty issue

Rejected: Add direct Stim/GATE_TABLE native instructions | stim.Circuit would still reject source program text before tsim parsing

Confidence: high

Scope-risk: narrow

Directive: Keep CCZ and CCX behavior aligned across program text parsing and Circuit.append

Tested: PYTHONPATH=src uv run pytest -q (1087 passed)

Tested: PYTHONPATH=src uv run ruff check src/tsim/utils/program_text.py src/tsim/circuit.py test/unit/test_circuit.py

Tested: PYTHONPATH=src uv run black --check src/tsim/utils/program_text.py src/tsim/circuit.py test/unit/test_circuit.py

Tested: PYTHONPATH=src uv run pyright src/tsim/circuit.py src/tsim/utils/program_text.py test/unit/test_circuit.py

Not-tested: SVG/timeline visualization for CCZ/CCX, per issue scope
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.

Feature Request: Add Support for native CCZ Gate

1 participant