Skip to content

Conversation

@Giacomo-Antonioli
Copy link

Add Gate Wrapper Methods and Comprehensive Tests

Overview

This PR implements wrapper methods for all gate types in the QCircuit class and adds comprehensive tests to ensure they work correctly.

What's New

1. Gate Wrapper Methods

Added convenient wrapper methods to QCircuit for all supported gate types:

  • Single-qubit gates: H(), X(), Y(), Z(), RX(), RY(), RZ(), Phase(), U2(), U3()
  • Two-qubit gates: CNOT(), CZ(), CY(), SWAP(), iSWAP(), CPhase(), CRX(), CRY(), CRZ(), CU2(), CU3()
  • Multi-controlled gates: MCX(), MCY(), MCZ(), MCRX(), MCRY(), MCRZ(), MCMG()
  • Matrix gates: MG(), MCMG()
  • Phase gates: Phase45(), Phase90(), T(), S()
  • Two-qubit rotations: RXX(), RYY(), RZZ()

2. Comprehensive Test Suite

Created extensive tests that verify:

  • Wrapper vs Full Class Equivalence: Each wrapper method creates gates identical to their full class counterparts
  • Parameter Accuracy: All gate parameters (angles, control states, matrices) are correctly set
  • Floating-Point Robustness: Tolerance-based comparisons handle numerical precision issues
  • Circuit Building: Multi-gate circuits and method chaining work correctly

3. Bug Fix

  • MCY Equals Method: Fixed a typo in the MCY gate's equals function that was preventing proper gate comparison

Key Features

Convenient API

% Before
circuit.push_back(qclab.qgates.Hadamard(0));

% After  
circuit.H(0);

Implemented wrappers for a comprehensive set of quantum gates to simplify circuit construction in the qclab library. Added extensive unit tests covering typical usage scenarios to ensure proper functionality.
- Updated test suite to use equals() method for comprehensive gate comparison
- Extended parameter validation across all gate types including angles and control states
- Fixed typo in MCY equals function to restore proper gate comparison
- Added floating-point tolerance for robust angle comparisons
- Maintained test coverage for all wrapper methods while improving verification accuracy
- Updated test suite to use equals() method for comprehensive gate comparison
- Extended parameter validation across all gate types including angles and control states
- Fixed typo in MCY equals function to restore proper gate comparison
- Added floating-point tolerance for robust angle comparisons
- Maintained test coverage for all wrapper methods while improving verification accuracy
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.

1 participant