How qpiai/quantum-sdk works
1. What this repository is
- qpiai_quantum is a Python SDK for quantum computing workflows: build circuits, simulate them locally, prepare benchmark states, run higher-level algorithms, visualize outputs, and submit jobs to QpiAI cloud resources.
2. Primary public API surface
- The package root is meant to be the user entry point. From the README and tree, it exposes circuit construction, authentication, common algorithms, state-preparation helpers, quantum-information objects, and visualization utilities.
- The sdk_notebooks/ directory serves as the main usage and learning surface, showing the intended end-to-end flows.
3. Circuit construction layer
- qpiai_quantum/circuit/ is the core model for quantum programs.
- It contains quantum and classical register abstractions, the Circuit type, random circuit generation, and circuit-specific exceptions.
- This layer is the place where users define gates, measurements, composition, and circuit structure before execution.
4. Execution and job management boundary
- qpiai_quantum/circuitmanager/ and qpiai_quantum/jobmanager/ are the orchestration boundary between circuit definitions and actual execution.
- jobmanager/ includes backend selection, execution engine, result packaging, SSE handling for status/progress updates, and job lifecycle management.
- backend.py and execution_engine.py suggest a split between “where to run” and “how to run,” which is important for local-vs-remote architecture diagrams.
5. Local simulation stack
- qpiai_quantum/simulator/ holds the local execution backend: base simulator, gate matrices, statevector simulation, and simulator result types.
- This is the core path for in-process circuit execution without cloud submission.
- qpiai_quantum/utils/gate_matrices.py is shared low-level math support for the simulator and circuit operations.
6. Quantum state and formalism layer
- qpiai_quantum/formalism/density_matrix/ and qpiai_quantum/quantum_info/ provide the mathematical representations used by the SDK.
- The density-matrix formalism is separate from the simulator implementation, implying support for both pure-state and mixed-state reasoning.
- quantum_info/statevector.py and quantum_info/density_matrix.py look like user-facing value objects or helpers for inspecting and manipulating states.
7. Algorithm library
- qpiai_quantum/algorithms/ is a structured algorithm suite with a shared base interface.
- It includes textbook algorithms such as Grover, Shor, QFT, QPE, Simon, Bernstein-Vazirani, Deutsch-Jozsa, QRNG, and amplitude estimation.
- The optimization subpackage is its own mini-stack: opt/problems, opt/ansatz, opt/solvers, and reusable optimizer/encoder utilities. This shows a clean separation between problem definition, circuit template, and iterative solver logic.
8. State preparation utilities
- qpiai_quantum/state_preparation/ provides ready-made entangled-state generators such as Bell, GHZ, W, and cluster states.
- These are likely thin circuit builders that plug directly into the main circuit/execution pipeline.
- They function as reusable building blocks for tutorials, tests, and algorithm setups.
9. Export/interchange and internal representation
- qpiai_quantum/iem/qasm/v2/ is the circuit export layer, centered on QASM v2 output.
- qpiai_quantum/icr/ appears to be an internal circuit representation/evolution layer used to transform or analyze circuits before export or execution.
- For architecture diagrams, treat these as the conversion boundary between the SDK’s native circuit model and external formats or backends.
10. Authentication and cloud access
- qpiai_quantum/authentication/ manages API-key-based login, user identity, and auth exceptions.
- The README indicates authentication is required for cloud access and is configured either programmatically or via qcloud.env.
- This layer is the gatekeeper for remote QCloud simulators and QPU submission.
11. Visualization subsystem
- qpiai_quantum/visualization/ is split by rendering technology: Matplotlib, Plotly, LaTeX, and Bloch-sphere/Q-sphere views.
- The plotting modules are separate from the circuit and simulator layers, which keeps visualization as a read-only presentation concern over circuits or results.
12. Packaging, examples, and verification
- The repo is packaged as a Python library (pyproject.toml, requirements.txt, uv.lock), with Python 3.8+ support.
- tests/ mirrors the major subsystems: algorithms, formalism, circuit operations, state preparation, and visualization.
- The notebooks and tests together indicate the intended architecture is SDK-first: library API plus executable examples, with coverage across both simulation and algorithmic workflows.
Main entry points: __init__.py Package root · circuit.py Circuit · base.py Algo base · visualizer.py Visualization
Components 22
Public API
User entry points and package-level interfaces.
- Package root · Top-level package exports and user-facing entry surface.
qpiai_quantum/__init__.py - Auth · API-key login, user identity, and authentication errors.
qpiai_quantum/authentication/auth.py
Core SDK
Circuit modeling, execution, simulation, and representations.
- Circuit · Core circuit and register abstractions for building quantum programs.
qpiai_quantum/circuit/circuit.py - Circuit manager · Bridges circuit definitions into execution and backend selection.
qpiai_quantum/circuitmanager/circuit_manager.py - Job manager · Backend, execution engine, result packaging, and job lifecycle handling.
qpiai_quantum/jobmanager/jobmanager.py - Backend · Selects where circuits execute, local or remote.
qpiai_quantum/jobmanager/backend.py - Execution engine · Executes jobs and coordinates execution-time behavior.
qpiai_quantum/jobmanager/execution_engine.py - Simulator · In-process circuit execution with statevector and gate support.
qpiai_quantum/simulator/base_simulator.py - Gate math · Shared low-level gate matrix utilities used by simulation and circuit logic.
qpiai_quantum/utils/gate_matrices.py - Density matrix · Mixed-state representations and density-matrix helpers.
qpiai_quantum/formalism/density_matrix/density_matrix.py - Quantum info · User-facing statevector and density-matrix value objects.
qpiai_quantum/quantum_info/statevector.py - ICR · Internal circuit representation and evolution utilities.
qpiai_quantum/icr/icr.py - QASM export · Exports native circuits to QASM v2.
qpiai_quantum/iem/qasm/v2/exporter.py - State prep · Reusable Bell, GHZ, W, and cluster state generators.
qpiai_quantum/state_preparation/ghz_state.py
Algorithms
Algorithm families and reusable optimization pieces.
- Algo base · Shared algorithm interface and standardization layer.
qpiai_quantum/algorithms/base.py - Textbook algs · Core algorithm implementations such as Grover, Shor, QFT, QPE, Simon, and Deutsch-Jozsa.
qpiai_quantum/algorithms/grover.py - Optimization · Problem definitions, ansatzes, solvers, encoders, and optimizers for variational workflows.
qpiai_quantum/algorithms/opt/problems/base.py
Presentation
Learning materials and visualization layers.
- Visualization · Matplotlib, Plotly, LaTeX, and Bloch/Q-sphere visual output layers.
qpiai_quantum/visualization/matplotlib_visualizer/visualizer.py - Notebooks · End-to-end usage and learning flows for the SDK.
sdk_notebooks/01_getting_started.ipynb
Quality
Tests and verification coverage.
- Algo tests · Coverage for algorithm implementations and optimizer behavior.
tests/algorithms/test_grover.py - Formalism tests · Coverage for density-matrix and special-state helpers.
tests/formalism/test_density_matrix_formalism.py - Viz tests · Coverage for visualization behavior.
tests/test_matplotlib_visualizer.py
Connections 29
- Package root → Auth: exports · Public API exposes cloud authentication.
- Package root → Circuit: exports · Package root exposes circuit construction.
- Package root → Algo base: exports · Package root exposes algorithms.
- Package root → State prep: exports · Package root exposes state preparation helpers.
- Package root → Quantum info: exports · Package root exposes quantum information objects.
- Package root → Visualization: exports · Package root exposes visualization utilities.
- Circuit → Circuit manager: hands off · Built circuits are passed into orchestration.
- Circuit manager → Job manager: submits · Circuit manager delegates job creation and execution.
- Job manager → Backend: selects · Jobs choose an execution backend.
- Job manager → Execution engine: runs through · Job manager coordinates the execution engine.
- Execution engine → Simulator: local run · Execution engine can run through the local simulator.
- Simulator → Gate math: uses · Simulator relies on shared gate matrix math.
- Simulator → Quantum info: produces · Simulation results are exposed as quantum state objects.
- Density matrix → Quantum info: aligns with · Density-matrix formalism parallels user-facing state types.
- Circuit → ICR: converts to · Native circuits can be transformed into an internal representation.
- ICR → QASM export: exports to · Internal representation supports QASM v2 export.
- State prep → Circuit: builds on · Prepared states are circuit builders feeding the core model.
- Algo base → Textbook algs: structures · Textbook algorithms follow a shared base interface.
- Algo base → Optimization: structures · Optimization algorithms build on shared abstractions.
- Optimization → State prep: uses · Variational workflows reuse circuit/state preparation building blocks.
- Visualization → Circuit: renders · Visualization presents circuits and related outputs.
- Visualization → Quantum info: renders · Visualization presents state and result data.
- Notebooks → Circuit: demonstrates · Notebooks show circuit construction flows.
- Notebooks → Algo base: demonstrates · Notebooks demonstrate algorithm usage.
- Notebooks → State prep: demonstrates · Notebooks demonstrate state preparation recipes.
- Algo tests → Textbook algs: covers · Algorithm tests verify standard algorithm modules.
- Algo tests → Optimization: covers · Algorithm tests verify optimization workflows.
- Formalism tests → Density matrix: covers · Formalism tests verify density-matrix behavior.
- Viz tests → Visualization: covers · Visualization tests verify rendering behavior.