quantumflow-sdk 0.3.0__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
api/main.py CHANGED
@@ -36,6 +36,9 @@ from api.auth import get_current_user, get_optional_user, get_db_session
36
36
  from api.routes.auth_routes import router as auth_router
37
37
  from api.routes.teleport_routes import router as teleport_router
38
38
  from api.routes.algorithm_routes import router as algorithm_router
39
+ from api.routes.chat_routes import router as chat_router
40
+ # Pipeline routes disabled - internal research only (not public API)
41
+ # from api.routes.pipeline_routes import router as pipeline_router
39
42
 
40
43
  # Import billing routes (optional - only if Stripe is configured)
41
44
  try:
@@ -120,6 +123,13 @@ app.include_router(teleport_router)
120
123
  # Include algorithm routes (QNN, Grover, QAOA, VQE, QSVM, QKD, QRNG, QFT)
121
124
  app.include_router(algorithm_router)
122
125
 
126
+ # Include QChat messaging routes (P2P encrypted messaging)
127
+ app.include_router(chat_router)
128
+
129
+ # Pipeline routes disabled - internal research only
130
+ # To enable: uncomment import and line below
131
+ # app.include_router(pipeline_router)
132
+
123
133
  # Include billing routes if available
124
134
  if BILLING_ENABLED and billing_router:
125
135
  app.include_router(billing_router)
@@ -160,14 +170,29 @@ async def compress_tokens(
160
170
  Compress tokens using quantum amplitude encoding.
161
171
 
162
172
  Achieves 53% token reduction via quantum superposition.
173
+
174
+ Options:
175
+ - `use_gray_code`: Enable Gray-code measurement protocol (arXiv:2601.00247)
176
+ which reduces measurement settings from O(N) to 2n+1.
163
177
  """
164
178
  if not _compressor:
165
179
  raise HTTPException(status_code=503, detail="Quantum compressor not initialized")
166
180
 
167
181
  start_time = time.perf_counter()
182
+ measurement_settings = None
183
+ gray_code_enabled = request.use_gray_code
168
184
 
169
185
  try:
170
- if request.execute:
186
+ if request.use_gray_code and request.execute:
187
+ # Use Gray-code measurement protocol
188
+ result, gray_result = _compressor.compress_with_gray_code(
189
+ tokens=request.tokens,
190
+ compression_level=request.compression_level,
191
+ shots=request.shots,
192
+ )
193
+ fidelity = result.execution_result.fidelity if result.execution_result else None
194
+ measurement_settings = gray_result.n_measurement_settings
195
+ elif request.execute:
171
196
  result = _compressor.compress_and_execute(
172
197
  tokens=request.tokens,
173
198
  compression_level=request.compression_level,
@@ -210,6 +235,8 @@ async def compress_tokens(
210
235
  fidelity=fidelity,
211
236
  execution_time_ms=execution_time,
212
237
  backend_used=request.backend,
238
+ measurement_settings=measurement_settings,
239
+ gray_code_enabled=gray_code_enabled,
213
240
  )
214
241
 
215
242
  except Exception as e:
api/models.py CHANGED
@@ -16,6 +16,10 @@ class CompressRequest(BaseModel):
16
16
  backend: str = Field(default="auto", description="Backend: auto, simulator, ibm")
17
17
  execute: bool = Field(default=False, description="Execute on quantum backend")
18
18
  shots: int = Field(default=1024, ge=1, le=10000)
19
+ use_gray_code: bool = Field(
20
+ default=False,
21
+ description="Use Gray-code measurement protocol (arXiv:2601.00247) for efficient readout"
22
+ )
19
23
 
20
24
 
21
25
  class CompressResponse(BaseModel):
@@ -29,6 +33,43 @@ class CompressResponse(BaseModel):
29
33
  fidelity: Optional[float] = None
30
34
  execution_time_ms: Optional[float] = None
31
35
  backend_used: str
36
+ # Gray-code specific fields
37
+ measurement_settings: Optional[int] = Field(
38
+ default=None,
39
+ description="Number of measurement settings used (2n+1 for Gray-code)"
40
+ )
41
+ gray_code_enabled: bool = Field(default=False)
42
+
43
+
44
+ # === SES VQE Models (arXiv:2601.00247) ===
45
+
46
+ class SESVQERequest(BaseModel):
47
+ """Request for Single Excitation Subspace VQE."""
48
+
49
+ n_sites: int = Field(..., ge=2, le=1024, description="Number of lattice sites")
50
+ on_site_energies: list[float] = Field(..., description="Energy at each site [h_11, h_22, ...]")
51
+ hopping_terms: list[tuple[int, int, float]] = Field(
52
+ ...,
53
+ description="Hopping amplitudes [(i, j, t_ij), ...] between sites"
54
+ )
55
+ max_iterations: int = Field(default=100, ge=10, le=1000)
56
+ backend: str = Field(default="auto")
57
+ shots: int = Field(default=1024, ge=100, le=10000)
58
+
59
+
60
+ class SESVQEResponse(BaseModel):
61
+ """Response from SES VQE computation."""
62
+
63
+ ground_energy: float
64
+ n_sites: int
65
+ n_qubits_used: int = Field(description="Logarithmic encoding: log₂(n_sites)")
66
+ qubit_reduction_percent: float
67
+ iterations: int
68
+ volumetric_cost: int
69
+ original_volumetric_cost: int
70
+ speedup: float
71
+ execution_time_ms: float
72
+ ansatz_type: str = "ses_binary"
32
73
 
33
74
 
34
75
  # === Gradient Models ===
@@ -506,6 +506,128 @@ async def vqe_compute(
506
506
  raise HTTPException(status_code=400, detail=str(e))
507
507
 
508
508
 
509
+ # ============================================================
510
+ # SES VQE - Single Excitation Subspace (arXiv:2601.00247)
511
+ # ============================================================
512
+
513
+ class SESVQERequest(BaseModel):
514
+ """Request for Single Excitation Subspace VQE.
515
+
516
+ Uses logarithmic qubit encoding from arXiv:2601.00247:
517
+ - N lattice sites encoded in log₂(N) qubits
518
+ - Exponential reduction in quantum resources
519
+ - Ideal for tight-binding Hamiltonians
520
+ """
521
+ n_sites: int = Field(..., ge=2, le=1024, description="Number of lattice sites")
522
+ on_site_energies: List[float] = Field(
523
+ ...,
524
+ description="Diagonal energies [h_11, h_22, ...] for each site"
525
+ )
526
+ hopping_terms: List[List] = Field(
527
+ ...,
528
+ description="Hopping terms [[i, j, t_ij], ...] between sites"
529
+ )
530
+ max_iterations: int = Field(default=100, ge=10, le=1000)
531
+ backend: str = Field(default="simulator")
532
+ shots: int = Field(default=1024, ge=100, le=10000)
533
+
534
+
535
+ class SESVQEResponse(BaseModel):
536
+ """Response from SES VQE computation."""
537
+ ground_energy: float
538
+ n_sites: int
539
+ n_qubits_used: int = Field(description="Logarithmic encoding: ⌈log₂(n_sites)⌉")
540
+ qubit_reduction_percent: float
541
+ iterations: int
542
+ energy_history: List[float]
543
+ volumetric_cost: int
544
+ original_volumetric_cost: int
545
+ speedup: float
546
+ execution_time_ms: float
547
+ ansatz_type: str = "ses_binary"
548
+
549
+
550
+ @router.post("/ses/solve", response_model=SESVQEResponse)
551
+ async def ses_vqe_solve(
552
+ request: SESVQERequest,
553
+ user: User = Depends(get_current_user), # Requires API key
554
+ ):
555
+ """
556
+ Run VQE with Single Excitation Subspace (SES) ansatz.
557
+
558
+ Based on arXiv:2601.00247 - achieves exponential reduction in
559
+ quantum resources for tight-binding Hamiltonians:
560
+
561
+ - **Qubit reduction**: N sites → log₂(N) qubits
562
+ - **Volumetric speedup**: O(N²) → O((log N)³)
563
+
564
+ Use cases:
565
+ - Tight-binding band structure calculations
566
+ - Solid-state physics simulations
567
+ - Material property prediction
568
+
569
+ Example (8-site chain):
570
+ ```json
571
+ {
572
+ "n_sites": 8,
573
+ "on_site_energies": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
574
+ "hopping_terms": [[0,1,-1.0], [1,2,-1.0], [2,3,-1.0], ...]
575
+ }
576
+ ```
577
+ Uses only 3 qubits instead of 8!
578
+ """
579
+ import math
580
+ from quantumflow.algorithms.machine_learning.vqe import run_ses_vqe, calculate_volumetric_cost
581
+
582
+ start_time = time.perf_counter()
583
+
584
+ try:
585
+ # Validate input
586
+ if len(request.on_site_energies) != request.n_sites:
587
+ raise ValueError(
588
+ f"on_site_energies length ({len(request.on_site_energies)}) "
589
+ f"must match n_sites ({request.n_sites})"
590
+ )
591
+
592
+ # Convert hopping terms to tuples
593
+ hopping_tuples = [
594
+ (int(h[0]), int(h[1]), complex(h[2]) if len(h) > 2 else complex(-1.0))
595
+ for h in request.hopping_terms
596
+ ]
597
+
598
+ # Run SES VQE
599
+ result = run_ses_vqe(
600
+ n_sites=request.n_sites,
601
+ on_site_energies=request.on_site_energies,
602
+ hopping_terms=hopping_tuples,
603
+ max_iterations=request.max_iterations,
604
+ backend=request.backend,
605
+ )
606
+
607
+ execution_time = (time.perf_counter() - start_time) * 1000
608
+
609
+ # Calculate efficiency metrics
610
+ n_qubits = math.ceil(math.log2(request.n_sites))
611
+ costs = calculate_volumetric_cost(request.n_sites, "ses_binary")
612
+
613
+ return SESVQEResponse(
614
+ ground_energy=result.ground_energy,
615
+ n_sites=request.n_sites,
616
+ n_qubits_used=n_qubits,
617
+ qubit_reduction_percent=(1 - n_qubits / request.n_sites) * 100,
618
+ iterations=result.n_iterations,
619
+ energy_history=result.energy_history,
620
+ volumetric_cost=costs["volumetric_cost"],
621
+ original_volumetric_cost=costs["original_volumetric_cost"],
622
+ speedup=costs["speedup"],
623
+ execution_time_ms=execution_time,
624
+ ansatz_type="ses_binary",
625
+ )
626
+
627
+ except Exception as e:
628
+ raise HTTPException(status_code=400, detail=str(e))
629
+
630
+
509
631
  # ============================================================
510
632
  # Algorithm Info Endpoint
511
633
  # ============================================================
@@ -863,6 +985,18 @@ async def list_algorithms():
863
985
  "endpoints": ["/v1/algorithms/vqe/compute"],
864
986
  "use_cases": ["Molecular simulation", "Ground state energy", "Quantum chemistry"],
865
987
  },
988
+ {
989
+ "id": "ses",
990
+ "name": "SES VQE",
991
+ "description": "Single Excitation Subspace VQE with logarithmic qubit encoding (arXiv:2601.00247)",
992
+ "endpoints": ["/v1/algorithms/ses/solve"],
993
+ "use_cases": ["Tight-binding Hamiltonians", "Band structure", "Solid-state physics"],
994
+ "features": {
995
+ "qubit_reduction": "N sites → log₂(N) qubits",
996
+ "speedup": "O(N²) → O((log N)³)",
997
+ "ansatz": "Binary-encoded SES with Gray-code measurement"
998
+ }
999
+ },
866
1000
  {
867
1001
  "id": "qsvm",
868
1002
  "name": "Quantum SVM",