Skip to content

Conversation

@shiavm006
Copy link
Contributor

Purpose of PR

Implements the T-gate (π/8 gate) across all backends to resolve the discrepancy where the documentation claimed T-gate support was "Added" but no implementation existed in the codebase.

Related Issues or PRs

Changes Made

  • Bug fix
  • New feature
  • Refactoring
  • Documentation
  • Test
  • CI/CD pipeline
  • Other

Breaking Changes

  • Yes
  • No

Checklist

  • Added or updated unit tests for all changes
  • Added or updated documentation for all changes
  • Successfully built and ran all unit tests or manual tests locally
  • PR title follows "MAHOUT-XXX: Brief Description" format (if related to an issue)
  • Code follows ASF guidelines

- Add apply_t_gate() method to QuMat class with validation
- Implement T-gate support in Qiskit, Cirq, and Amazon Braket backends
- Restore T-gate documentation in basic_gates.md to match implementation

Fixes apache#681
@shiavm006
Copy link
Contributor Author

shiavm006 commented Dec 6, 2025

cc @guan404ming @rawkintrevo is it correct what r ur opinions on it
and can we connect on slack ?
or any other platform would like to know u guys a bit ?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the T-gate (π/8 gate) across all quantum computing backends (Qiskit, Cirq, Amazon Braket) to resolve an inconsistency where the documentation claimed T-gate support existed but no implementation was present in the codebase. The T-gate is essential for universal quantum computation when combined with Hadamard and CNOT gates.

Key Changes

  • Added apply_t_gate() method to the main QuMat API class with comprehensive docstring
  • Implemented backend-specific T-gate functions for Qiskit, Cirq, and Amazon Braket
  • Updated documentation to reflect that T-gate is now fully implemented (removed "New Addition" label)

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
qumat/qumat.py Added apply_t_gate method to QuMat class with validation and backend delegation
qumat/qiskit_backend.py Implemented T-gate using Qiskit's native t() method
qumat/cirq_backend.py Implemented T-gate using Cirq's T gate on LineQubit
qumat/amazon_braket_backend.py Implemented T-gate using Amazon Braket's t() method
docs/basic_gates.md Removed "(New Addition)" label from T-Gate section header

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

qumat/qumat.py Outdated
Comment on lines 257 to 258
Applies a π/4 phase shift to the qubit. Essential for universal
quantum computation when combined with Hadamard and CNOT gates.
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring incorrectly states "Applies a π/4 phase shift" but the T-gate actually applies a π/4 phase to the |1⟩ state, not a π/4 phase shift to the overall state. More accurately, the T-gate can be described as applying a relative phase of π/4 or introducing a phase of e^(iπ/4) = e^(i45°) to the |1⟩ state. The phase shift terminology is potentially misleading.

Suggested change
Applies a π/4 phase shift to the qubit. Essential for universal
quantum computation when combined with Hadamard and CNOT gates.
Applies a relative phase of π/4 (i.e., multiplies the |1state by e^(/4)).
Essential for universal quantum computation when combined with Hadamard and CNOT gates.

Copilot uses AI. Check for mistakes.
Comment on lines 254 to 266
def apply_t_gate(self, qubit_index):
"""Apply a T-gate (π/8 gate) to the specified qubit.
Applies a π/4 phase shift to the qubit. Essential for universal
quantum computation when combined with Hadamard and CNOT gates.
:param qubit_index: Index of the qubit.
:type qubit_index: int
:raises RuntimeError: If the circuit has not been initialized.
"""
self._ensure_circuit_initialized()
self._validate_qubit_index(qubit_index)
self.backend_module.apply_t_gate(self.circuit, qubit_index)
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added apply_t_gate method lacks test coverage. The test file testing/test_single_qubit_gates.py has comprehensive test classes for all other single-qubit gates (TestPauliXGate, TestPauliYGate, TestPauliZGate, TestHadamardGate, TestNOTGate, TestUGate), but no TestTGate class exists. Consider adding a test class similar to the existing ones that verifies:

  1. T-gate state transitions (e.g., T|0⟩ = |0⟩, T|1⟩ applies phase)
  2. T-gate phase accumulation (T^8 = I)
  3. Cross-backend consistency
  4. Combination with Hadamard to verify phase effect

Copilot uses AI. Check for mistakes.
@shiavm006
Copy link
Contributor Author

cc @guan404ming

Copy link
Member

@guan404ming guan404ming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@guan404ming
Copy link
Member

guan404ming commented Dec 11, 2025

Need to resolve the pre-commit error.

@shiavm006
Copy link
Contributor Author

Need to resolve the pre-commit error.

issues resolved

@rich7420
Copy link
Contributor

@guan404ming do you want to take another look?

@guan404ming guan404ming merged commit 8f4ccc3 into apache:main Dec 12, 2025
3 checks passed
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.

[Docs] T-gate documented in basic_gates.md but not implemented in Qumat

3 participants