Skip to content

Comments

Add bulk initialization methods for GraphState: from_graph() and from_base_graph_state() (#120)#121

Merged
masa10-f merged 10 commits intomasterfrom
issue/120-add-bulk-init-methods
Oct 29, 2025
Merged

Add bulk initialization methods for GraphState: from_graph() and from_base_graph_state() (#120)#121
masa10-f merged 10 commits intomasterfrom
issue/120-add-bulk-init-methods

Conversation

@masa10-f
Copy link
Collaborator

Summary

  • Added from_graph() class method for flexible graph initialization with arbitrary node types (strings, tuples, etc.)
  • Added from_base_graph_state() class method for creating new GraphState instances from existing BaseGraphState objects
  • Comprehensive test suite with 20+ test cases for both initialization methods
  • Updated example code (draw_graph.py) to use the new initialization methods

Test plan

  • Run pytest tests/test_graphstate_bulk_init.py -v - All 20+ tests pass
  • Run pytest - All existing tests still pass
  • Run ruff check graphqomb/ tests/ - No linting errors
  • Run mypy graphqomb/ - Type checking passes
  • Updated CHANGELOG.md following Keep a Changelog format
  • Verified example code works with new methods

Closes #120

🤖 Generated with Claude Code

masa10-f and others added 8 commits October 27, 2025 21:36
…_base_graph_state()

Implements issue #120 by adding two new classmethod factory methods to GraphState:

1. from_graph(): Create a GraphState from nodes and edges with arbitrary hashable node
   identifiers (strings, tuples, etc.). Returns both the created GraphState and a
   mapping from external node IDs to internal indices.

2. from_base_graph_state(): Create a new GraphState by copying from an existing
   BaseGraphState instance, with optional control over LocalClifford operator copying.

These methods improve usability by enabling cleaner graph construction patterns and
allowing bulk initialization instead of adding nodes and edges one at a time.

- Comprehensive input validation with clear error messages
- Support for arbitrary node types via TypeVar
- Preservation of node order for predictable index assignment
- Full test coverage with 20 test cases covering various scenarios

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
@masa10-f masa10-f self-assigned this Oct 27, 2025
@masa10-f masa10-f added the enhancement New feature or request label Oct 27, 2025
@codecov
Copy link

codecov bot commented Oct 27, 2025

Codecov Report

❌ Patch coverage is 89.70588% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.35%. Comparing base (d794b08) to head (b6bbb15).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #121      +/-   ##
==========================================
+ Coverage   67.58%   68.35%   +0.77%     
==========================================
  Files          21       21              
  Lines        1968     2035      +67     
  Branches      300      326      +26     
==========================================
+ Hits         1330     1391      +61     
- Misses        590      592       +2     
- Partials       48       52       +4     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@masa10-f masa10-f requested a review from d1ssk October 27, 2025 13:16
@masa10-f masa10-f merged commit 2edc5f2 into master Oct 29, 2025
23 checks passed
@masa10-f masa10-f deleted the issue/120-add-bulk-init-methods branch October 29, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add bulk initialization methods for GraphState: from_graph() and from_base_graph_state()

2 participants