Skip to content

Add Pauli Y and Z gates#4

Open
blackboxprogramming wants to merge 1 commit intomainfrom
codex/proceed-to-the-next-task
Open

Add Pauli Y and Z gates#4
blackboxprogramming wants to merge 1 commit intomainfrom
codex/proceed-to-the-next-task

Conversation

@blackboxprogramming
Copy link
Owner

Summary

  • add Pauli-Y and Pauli-Z gate helpers to the quantum circuit simulator
  • document the expanded gate set in the README
  • extend the test suite to cover the new gates and their phase behaviour

Testing

  • pytest -q

Codex Task

Copilot AI review requested due to automatic review settings December 3, 2025 03:04
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copy link

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 extends the quantum circuit simulator with two additional Pauli gates (Y and Z), expanding the available single-qubit operations beyond the existing Hadamard and Pauli-X gates.

  • Added Pauli-Y and Pauli-Z gate methods to the QuantumCircuit class
  • Implemented corresponding unitary matrices with correct complex phase factors
  • Added comprehensive tests verifying both probability outcomes and phase behavior

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
quantum_simulator.py Implements pauli_y() and pauli_z() methods with detailed docstrings and defines their matrix representations
tests/test_quantum_simulator.py Adds two test cases verifying Y-gate bit-flip with phase and Z-gate phase modification without probability changes
README.md Updates feature description to include Pauli-X/Y/Z gates in the gate set listing

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

Copy link

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


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

Comment on lines +23 to +30
def test_pauli_y_flips_state_with_phase():
circuit = QuantumCircuit(1)
circuit.pauli_y(0)
probs = circuit.probabilities()
assert probs["1"] == pytest.approx(1.0)
assert probs["0"] == pytest.approx(0.0)


Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

test_pauli_y_flips_state_with_phase only asserts computational-basis probabilities after pauli_y(0) on |0⟩, which cannot observe the introduced phase (the same assertions would pass for an incorrect implementation like Pauli-X). To actually validate the phase behaviour, add an interference-based check (e.g., prepare a superposition with hadamard, apply pauli_y, then hadamard again and assert the resulting probabilities), or rename the test to avoid claiming phase coverage.

Suggested change
def test_pauli_y_flips_state_with_phase():
circuit = QuantumCircuit(1)
circuit.pauli_y(0)
probs = circuit.probabilities()
assert probs["1"] == pytest.approx(1.0)
assert probs["0"] == pytest.approx(0.0)
def test_pauli_y_flips_state_with_phase():
# Basic flip behaviour from |0⟩ to |1⟩
circuit = QuantumCircuit(1)
circuit.pauli_y(0)
probs = circuit.probabilities()
assert probs["1"] == pytest.approx(1.0)
assert probs["0"] == pytest.approx(0.0)
# Interference-based check to validate the Pauli-Y phase:
# H |0⟩ -> (|0⟩ + |1⟩)/√2
# Y then H should result in |1⟩ with probability 1,
# whereas an incorrect Pauli-X implementation would give |0⟩.
circuit = QuantumCircuit(1)
circuit.hadamard(0)
circuit.pauli_y(0)
circuit.hadamard(0)
probs = circuit.probabilities()
assert probs["1"] == pytest.approx(1.0)
assert probs["0"] == pytest.approx(0.0)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants