Skip to content

Conversation

@nulinspiratie
Copy link
Contributor

Summary

Enable Channel classes to inherit from both Channel and Qubit, allowing macros and operations to be directly associated with channels. This is particularly useful for cases where the channel is the natural abstraction level, such as flattop macros in spectroscopy experiments.

Features

  • Multiple Inheritance Support: Channels can now inherit from Qubit, enabling hybrid classes
  • Channel Self-Inclusion: When a Qubit is also a Channel, it includes itself in the channels dictionary using its name as the key
  • Macro Support: Enables direct channel-level macros through inherited QuantumComponent functionality
  • Full Test Coverage: Comprehensive testing with different MRO orderings (Channel-first, Qubit-first) and ID types (string, integer)

Usage Example

from quam import QuamRoot
from quam.core import quam_dataclass
from quam.components.channels import SingleChannel
from quam.components.quantum_components.qubit import Qubit

# Create a hybrid channel-qubit class
@quam_dataclass
class HybridChannelQubit(SingleChannel, Qubit):
    pass

# Use it with direct macros and channel operations
hybrid = HybridChannelQubit(id="ch1", opx_output=port)

# Hybrid object now supports:
# - Channel operations (play, measure)
# - Qubit operations (align, get_pulse)
# - Direct macro attachment via Qubit.macros

Implementation

  • Modified Qubit.channels property to include self when isinstance(self, Channel)
  • Added explicit test test_hybrid_channels_dict_key_matches_name verifying the channel key matches self.name
  • Tested with multiple inheritance scenarios covering both MRO orderings

Test Results

  • All 7 hybrid channel component tests pass
  • Full test suite: 586 tests pass
  • No regressions introduced

Scope

Fixes GitHub issue #174. This change is backward compatible—existing code continues to work unchanged.

Allow Channel classes to inherit from both Channel and Qubit, enabling
macros and operations to be directly associated with channels. This is
useful for cases where the channel is the natural abstraction level,
such as flattop macros in spectroscopy experiments.

Changes:
- Modify Qubit.channels property to include self when isinstance(self, Channel)
- Add comprehensive test coverage verifying channel key matches self.name
- Test hybrid inheritance scenarios with different MRO orderings
- Verify channel key integration works with both string and integer IDs

Fixes: #174
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.

2 participants