Skip to content

Add Python integration tests for quantum circuit API #4

Description

@tianyan-admin

Summary

The cqlib Python bindings (binding-python) have a core test suite in tests/python/, but some circuit API methods lack dedicated test coverage. This issue is to add integration tests for circuit construction and manipulation APIs.

What to do

Add Python tests in tests/python/ covering the following circuit operations:

  1. Basic gate operations

    • Test Circuit.h(), Circuit.cx(), Circuit.x(), Circuit.y(), Circuit.z()
    • Verify num_qubits and operation count
  2. Parameterized circuits

    • Test Circuit.rx(), Circuit.ry(), Circuit.rz() with Parameter
    • Test assign_parameters() with various parameter values
  3. Edge cases

    • Empty circuit (zero qubits)
    • Large circuits (e.g., 100+ qubits)
    • Invalid qubit indices

Skills needed

  • Basic Python programming
  • Basic understanding of quantum circuits
  • Experience with pytest is a plus

Getting started

git clone https://github.com/cq-lib/cqlib.git
cd cqlib

# Set up Python environment
python3 -m venv .venv
source .venv/bin/activate
pip install maturin pytest

# Build Python bindings
maturin develop -m crates/binding-python/Cargo.toml

# Run existing tests
pytest tests/python/ -v

# Add your tests in tests/python/ and run them
pytest tests/python/ -v

Example test

# tests/python/test_circuit_basics.py
from cqlib import Circuit

def test_bell_state():
    """Test basic Bell state construction"""
    qc = Circuit(2)
    qc.h(0)
    qc.cx(0, 1)

    assert qc.num_qubits == 2
    assert len(qc.operations) == 2

Acceptance criteria

  • Tests for at least 3 different gate types
  • Tests for parameterized circuits with assign_parameters()
  • At least one edge-case test
  • All tests pass with pytest tests/python/ -v
  • Code passes ruff check

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions