refactor: Add error handling and API encapsulation#2
Merged
Conversation
Major refactoring to make the library more modular and professional: - Add comprehensive error handling module (src/error.rs) using thiserror - Encapsulate struct fields (State, Circuit, Operation) with public getters - Replace Rc with Arc for thread-safe shared ownership - Update all methods to return Result<T, LogosQError> for proper error handling - Fix all tests to use new API (getters, Result handling) - Fix all examples to use new API and handle Results - Fix doctest in MatrixGate documentation - Remove all compilation warnings Changes: - State: vector and num_qubits fields now private with getters - Circuit: operations, num_qubits, name fields now private with getters - Operation: gate, qubits, name fields now private with getters - All circuit operations now return Result types - All state operations now return Result types - Updated 44 files with 1957 insertions and 649 deletions All tests pass (131 tests) and all doctests pass (17 tests). All examples compile without warnings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Major refactoring to make the library more modular and professional:
Changes:
All tests pass (131 tests) and all doctests pass (17 tests). All examples compile without warnings.
Note
Refactors core APIs to return Result with structured errors, encapsulates internals with getters, switches to Arc, and updates all modules/examples/tests for the new error- and feature-gated parallel API.
src/error.rswithLogosQErrorand crate-wideResult<T>.Circuit::add_operation,execute,execute_and_measure,expectation,State::measure_qubit) to returnResult.State,Circuit, andOperation; add getters (num_qubits(),operations(),name(),vector(), etc.).RcwithArcfor gates/noise models; adjust trait bounds for thread safety.parallelfeature; conditionally use Rayon for state ops and measurements.Result,Arc).LogosQErrorandResult.Result(unwrap()), plus a newexamples/gradient_bugs.rs.0.2.1; addthiserror,rand,rayon(optional),approx,plotters,rustfft; update README install snippet.Written by Cursor Bugbot for commit 6746d87. This will update automatically on new commits. Configure here.