Skip to content

Conversation

@ACE07-Sev
Copy link
Member

@ACE07-Sev ACE07-Sev commented Jul 30, 2025

Refactored quick.primitives for less code bloat and clarity. This consisted of deprecating quick.primitives.Bra and quick.primitives.Ket and creating a new primitive class called quick.primitives.Statevector. quick.primitives.Bra in specific will not be supported due to incompatibility of its compilation to statevectors, and by extension infeasibility of its original purpose which was to compile Bra-Ket expressions (inner-products, outer products, etc.) to circuits.

This PR aims to provide clear purpose for quick.primitives. Primitives are conventionally used in three main manners:
1) Classical simulation of circuits to extract statevectors/unitaries: This task is done via circuit frameworks and quick.backend and thus we avoid redoing this feature in primitives to comply with python zen, specifically "There should be one-- and preferably only one --obvious way to do it.", meaning any and all executions of the circuit are to be done only via backends or default backends present in the circuit frameworks.
2) Datatype representation to annotate a variable as a Statevector/Operator: This was the way quick.primitives operated mainly, which leads to code smell and incoherent usage of such dataclass and NDArray from numpy. We avoid this, and only use primitives where their functionality as described in (3) are needed.
3) Containing primitive specific functionality for reusability: Normalization, padding, etc. are functionality that are widely utilized with such entities, and thus the main focus of quick.primitives now is to provide a class that contains such functionality for ease of use. That means users do not need to use quick.primitives if they do not use such functionality and can simply use NDArray with quick.predicates to ensure a numpy array satisfies their requirements.

This PR is first of many to align with the improved, rot-free development pattern in mind.

@codacy-production
Copy link

codacy-production bot commented Jul 30, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.47% (target: -1.00%) 91.31%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (ed2ed7c) 4387 3926 89.49%
Head commit (5730c60) 4362 (-25) 3924 (-2) 89.96% (+0.47%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#63) 518 473 91.31%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@codecov
Copy link

codecov bot commented Jul 30, 2025

Codecov Report

❌ Patch coverage is 91.31274% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.95%. Comparing base (ed2ed7c) to head (5730c60).
⚠️ Report is 14 commits behind head on 0.0.0-release.

Files with missing lines Patch % Lines
...uick/circuit/gate_matrix/controlled_qubit_gates.py 60.00% 18 Missing ⚠️
quick/primitives/statevector.py 91.36% 12 Missing ⚠️
quick/predicates/predicates.py 92.00% 4 Missing ⚠️
quick/primitives/operator.py 93.33% 4 Missing ⚠️
quick/primitives/contraction.py 88.88% 3 Missing ⚠️
quick/metrics/metrics.py 83.33% 2 Missing ⚠️
quick/circuit/circuit.py 97.72% 1 Missing ⚠️
...ick/synthesis/statepreparation/statepreparation.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           0.0.0-release      #63      +/-   ##
=================================================
+ Coverage          89.49%   89.95%   +0.46%     
=================================================
  Files                 63       63              
  Lines               4387     4362      -25     
=================================================
- Hits                3926     3924       -2     
+ Misses               461      438      -23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

ACE07-Sev added 11 commits July 30, 2025 19:57
….Statevector`.

- Given `quick.metrics.calculate_entanglement_entropy_slope()` uses only statevectors, the code migrates from `qiskit.quantum_info.partial_trace()` to native `quick.primitives.Statevector.partial_trace()`.
- Added testers for new functionality.
…d `quick.primitives.Operator`.

- Added `__matmul__` dunder to `quick.primitives.Operator`.
- Updated `quick.primitives` testers.
…evector.

- Added testers for the recent additions to primitives.
- Fixed a bug with `quick.synthesis.unitarypreparation.ShannonDecomposition` with the `QUBIT_KEYS` missing some keys causing IndexError.
- Modified `get_counts` for `quick.circuit.PennylaneCircuit` to account for the version difference functionality.
- Updated `.decompose()` of `quick.circuit.Circuit` for better clarity and performance.
- Fixed a bug with `.control()` in `quick.circuit.Circuit` where gates that do not have C, MC- methods available now get decomposed before being converted to controlled format.
- Deprecated `quick.circuit.gate_matrix.Gate`, which will be brought back properly in quick's rewrite.
- Added `.control()` to `quick.primitives.Operator` for calculating the controlled unitary of a unitary.
- Brought `Scalar` back to `__mul__` for `quick.primitives.Operator` and `quick.primitives.Statevector` to act as global phase.
- Added testers for the additions.
- Added constructor from general matrix to `quick.primitives.Operator` via using SVD.
- Slightly updated two qubit decomposition.
- Added new test cases for weyl coordinates.
@ACE07-Sev ACE07-Sev self-assigned this Oct 18, 2025
@ACE07-Sev ACE07-Sev merged commit 606525c into 0.0.0-release Oct 18, 2025
21 of 23 checks passed
@ACE07-Sev ACE07-Sev deleted the primitives-remake branch October 18, 2025 11:24
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