quantumflow-sdk 0.1.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.
Files changed (60) hide show
  1. api/__init__.py +1 -0
  2. api/auth.py +208 -0
  3. api/main.py +403 -0
  4. api/models.py +137 -0
  5. api/routes/__init__.py +1 -0
  6. api/routes/auth_routes.py +234 -0
  7. api/routes/teleport_routes.py +415 -0
  8. db/__init__.py +15 -0
  9. db/crud.py +319 -0
  10. db/database.py +93 -0
  11. db/models.py +197 -0
  12. quantumflow/__init__.py +47 -0
  13. quantumflow/algorithms/__init__.py +48 -0
  14. quantumflow/algorithms/compression/__init__.py +7 -0
  15. quantumflow/algorithms/compression/amplitude_amplification.py +189 -0
  16. quantumflow/algorithms/compression/qft_compression.py +133 -0
  17. quantumflow/algorithms/compression/token_compression.py +261 -0
  18. quantumflow/algorithms/cryptography/__init__.py +6 -0
  19. quantumflow/algorithms/cryptography/qkd.py +205 -0
  20. quantumflow/algorithms/cryptography/qrng.py +231 -0
  21. quantumflow/algorithms/machine_learning/__init__.py +7 -0
  22. quantumflow/algorithms/machine_learning/qnn.py +276 -0
  23. quantumflow/algorithms/machine_learning/qsvm.py +249 -0
  24. quantumflow/algorithms/machine_learning/vqe.py +229 -0
  25. quantumflow/algorithms/optimization/__init__.py +7 -0
  26. quantumflow/algorithms/optimization/grover.py +223 -0
  27. quantumflow/algorithms/optimization/qaoa.py +251 -0
  28. quantumflow/algorithms/optimization/quantum_annealing.py +237 -0
  29. quantumflow/algorithms/utility/__init__.py +6 -0
  30. quantumflow/algorithms/utility/circuit_optimizer.py +194 -0
  31. quantumflow/algorithms/utility/error_correction.py +330 -0
  32. quantumflow/api/__init__.py +1 -0
  33. quantumflow/api/routes/__init__.py +4 -0
  34. quantumflow/api/routes/billing_routes.py +520 -0
  35. quantumflow/backends/__init__.py +33 -0
  36. quantumflow/backends/base_backend.py +184 -0
  37. quantumflow/backends/braket_backend.py +345 -0
  38. quantumflow/backends/ibm_backend.py +112 -0
  39. quantumflow/backends/simulator_backend.py +86 -0
  40. quantumflow/billing/__init__.py +25 -0
  41. quantumflow/billing/models.py +126 -0
  42. quantumflow/billing/stripe_service.py +619 -0
  43. quantumflow/core/__init__.py +12 -0
  44. quantumflow/core/entanglement.py +164 -0
  45. quantumflow/core/memory.py +147 -0
  46. quantumflow/core/quantum_backprop.py +394 -0
  47. quantumflow/core/quantum_compressor.py +309 -0
  48. quantumflow/core/teleportation.py +386 -0
  49. quantumflow/integrations/__init__.py +107 -0
  50. quantumflow/integrations/autogen_tools.py +501 -0
  51. quantumflow/integrations/crewai_agents.py +425 -0
  52. quantumflow/integrations/crewai_tools.py +407 -0
  53. quantumflow/integrations/langchain_memory.py +385 -0
  54. quantumflow/integrations/langchain_tools.py +366 -0
  55. quantumflow/integrations/mcp_server.py +575 -0
  56. quantumflow_sdk-0.1.0.dist-info/METADATA +190 -0
  57. quantumflow_sdk-0.1.0.dist-info/RECORD +60 -0
  58. quantumflow_sdk-0.1.0.dist-info/WHEEL +5 -0
  59. quantumflow_sdk-0.1.0.dist-info/entry_points.txt +2 -0
  60. quantumflow_sdk-0.1.0.dist-info/top_level.txt +3 -0
@@ -0,0 +1,425 @@
1
+ """
2
+ CrewAI Agents for QuantumFlow.
3
+
4
+ Pre-configured quantum-enhanced agents for common tasks:
5
+ - QuantumResearchAgent: Research and analysis
6
+ - QuantumOptimizerAgent: Optimization tasks
7
+ - QuantumAnalystAgent: Data analysis
8
+ """
9
+
10
+ from typing import Any, Optional, List, Dict
11
+
12
+ try:
13
+ from crewai import Agent, Task, Crew, Process
14
+ CREWAI_AVAILABLE = True
15
+ except ImportError:
16
+ CREWAI_AVAILABLE = False
17
+ # Dummy classes
18
+ class Agent:
19
+ pass
20
+ class Task:
21
+ pass
22
+ class Crew:
23
+ pass
24
+
25
+ from quantumflow.integrations.crewai_tools import (
26
+ get_quantum_crew_tools,
27
+ QuantumCompressCrewTool,
28
+ QuantumOptimizeCrewTool,
29
+ QuantumAnalyzeCrewTool,
30
+ QuantumSearchCrewTool,
31
+ )
32
+
33
+
34
+ def _check_crewai():
35
+ """Check if CrewAI is available."""
36
+ if not CREWAI_AVAILABLE:
37
+ raise ImportError(
38
+ "CrewAI is not installed. "
39
+ "Install it with: pip install crewai crewai-tools"
40
+ )
41
+
42
+
43
+ class QuantumResearchAgent:
44
+ """
45
+ Quantum-enhanced research agent.
46
+
47
+ Specializes in:
48
+ - Literature search with quantum speedup
49
+ - Data compression for large contexts
50
+ - Pattern recognition in research data
51
+
52
+ Example:
53
+ from quantumflow.integrations import QuantumResearchAgent
54
+
55
+ agent = QuantumResearchAgent.create(llm=my_llm)
56
+ # Use with CrewAI tasks
57
+ """
58
+
59
+ @classmethod
60
+ def create(
61
+ cls,
62
+ llm: Any = None,
63
+ backend: str = "simulator",
64
+ verbose: bool = True,
65
+ **kwargs
66
+ ) -> Agent:
67
+ """
68
+ Create a quantum research agent.
69
+
70
+ Args:
71
+ llm: Language model to use
72
+ backend: Quantum backend ("simulator" or "ibm")
73
+ verbose: Enable verbose output
74
+ **kwargs: Additional Agent parameters
75
+
76
+ Returns:
77
+ CrewAI Agent configured for quantum research
78
+ """
79
+ _check_crewai()
80
+
81
+ tools = [
82
+ QuantumSearchCrewTool(backend=backend),
83
+ QuantumCompressCrewTool(backend=backend),
84
+ QuantumAnalyzeCrewTool(backend=backend),
85
+ ]
86
+
87
+ agent_kwargs = {
88
+ "role": "Quantum Research Specialist",
89
+ "goal": (
90
+ "Conduct thorough research using quantum-enhanced search and analysis. "
91
+ "Leverage Grover's algorithm for fast information retrieval and "
92
+ "quantum compression for handling large datasets efficiently."
93
+ ),
94
+ "backstory": (
95
+ "You are an expert researcher with access to quantum computing tools. "
96
+ "You can search through vast databases with quadratic speedup using "
97
+ "Grover's algorithm, compress large contexts using quantum amplitude "
98
+ "encoding, and identify patterns using quantum analysis. Your quantum "
99
+ "tools give you an edge in processing and analyzing information faster "
100
+ "than classical methods."
101
+ ),
102
+ "tools": tools,
103
+ "verbose": verbose,
104
+ "allow_delegation": True,
105
+ }
106
+
107
+ if llm:
108
+ agent_kwargs["llm"] = llm
109
+
110
+ agent_kwargs.update(kwargs)
111
+ return Agent(**agent_kwargs)
112
+
113
+
114
+ class QuantumOptimizerAgent:
115
+ """
116
+ Quantum-enhanced optimization agent.
117
+
118
+ Specializes in:
119
+ - QAOA for combinatorial optimization
120
+ - Portfolio optimization
121
+ - Resource allocation
122
+ - Scheduling problems
123
+
124
+ Example:
125
+ from quantumflow.integrations import QuantumOptimizerAgent
126
+
127
+ agent = QuantumOptimizerAgent.create(llm=my_llm)
128
+ """
129
+
130
+ @classmethod
131
+ def create(
132
+ cls,
133
+ llm: Any = None,
134
+ backend: str = "simulator",
135
+ verbose: bool = True,
136
+ **kwargs
137
+ ) -> Agent:
138
+ """
139
+ Create a quantum optimization agent.
140
+
141
+ Args:
142
+ llm: Language model to use
143
+ backend: Quantum backend
144
+ verbose: Enable verbose output
145
+
146
+ Returns:
147
+ CrewAI Agent configured for quantum optimization
148
+ """
149
+ _check_crewai()
150
+
151
+ tools = [
152
+ QuantumOptimizeCrewTool(backend=backend),
153
+ QuantumAnalyzeCrewTool(backend=backend),
154
+ ]
155
+
156
+ agent_kwargs = {
157
+ "role": "Quantum Optimization Expert",
158
+ "goal": (
159
+ "Solve complex optimization problems using quantum algorithms. "
160
+ "Apply QAOA for NP-hard problems like portfolio optimization, "
161
+ "scheduling, routing, and resource allocation."
162
+ ),
163
+ "backstory": (
164
+ "You are a quantum optimization specialist with deep expertise in "
165
+ "the Quantum Approximate Optimization Algorithm (QAOA). You can "
166
+ "tackle combinatorial optimization problems that are intractable "
167
+ "for classical computers. Your toolkit includes solvers for MaxCut, "
168
+ "portfolio optimization, traveling salesman, and other NP-hard problems. "
169
+ "You understand the trade-offs between solution quality and quantum "
170
+ "resources, and can recommend the best approach for each problem."
171
+ ),
172
+ "tools": tools,
173
+ "verbose": verbose,
174
+ "allow_delegation": False,
175
+ }
176
+
177
+ if llm:
178
+ agent_kwargs["llm"] = llm
179
+
180
+ agent_kwargs.update(kwargs)
181
+ return Agent(**agent_kwargs)
182
+
183
+
184
+ class QuantumAnalystAgent:
185
+ """
186
+ Quantum-enhanced data analyst agent.
187
+
188
+ Specializes in:
189
+ - Pattern recognition
190
+ - Anomaly detection
191
+ - Correlation analysis
192
+ - Data compression
193
+
194
+ Example:
195
+ from quantumflow.integrations import QuantumAnalystAgent
196
+
197
+ agent = QuantumAnalystAgent.create(llm=my_llm)
198
+ """
199
+
200
+ @classmethod
201
+ def create(
202
+ cls,
203
+ llm: Any = None,
204
+ backend: str = "simulator",
205
+ verbose: bool = True,
206
+ **kwargs
207
+ ) -> Agent:
208
+ """
209
+ Create a quantum analyst agent.
210
+
211
+ Args:
212
+ llm: Language model to use
213
+ backend: Quantum backend
214
+ verbose: Enable verbose output
215
+
216
+ Returns:
217
+ CrewAI Agent configured for quantum analysis
218
+ """
219
+ _check_crewai()
220
+
221
+ tools = [
222
+ QuantumAnalyzeCrewTool(backend=backend),
223
+ QuantumCompressCrewTool(backend=backend),
224
+ QuantumSearchCrewTool(backend=backend),
225
+ ]
226
+
227
+ agent_kwargs = {
228
+ "role": "Quantum Data Analyst",
229
+ "goal": (
230
+ "Analyze data using quantum-enhanced techniques. "
231
+ "Detect patterns, identify anomalies, and find correlations "
232
+ "that classical methods might miss."
233
+ ),
234
+ "backstory": (
235
+ "You are a data analyst empowered with quantum computing tools. "
236
+ "Your quantum analysis capabilities allow you to find hidden patterns "
237
+ "in data through quantum amplitude encoding, detect anomalies using "
238
+ "quantum-enhanced statistical methods, and compress large datasets "
239
+ "while preserving essential information. You excel at extracting "
240
+ "insights from complex, high-dimensional data."
241
+ ),
242
+ "tools": tools,
243
+ "verbose": verbose,
244
+ "allow_delegation": True,
245
+ }
246
+
247
+ if llm:
248
+ agent_kwargs["llm"] = llm
249
+
250
+ agent_kwargs.update(kwargs)
251
+ return Agent(**agent_kwargs)
252
+
253
+
254
+ def create_quantum_crew(
255
+ llm: Any = None,
256
+ backend: str = "simulator",
257
+ tasks: Optional[List[Dict[str, Any]]] = None,
258
+ process: str = "sequential",
259
+ verbose: bool = True,
260
+ ) -> Crew:
261
+ """
262
+ Create a complete quantum-enhanced crew.
263
+
264
+ Creates a team with:
265
+ - Quantum Research Specialist
266
+ - Quantum Optimization Expert
267
+ - Quantum Data Analyst
268
+
269
+ Args:
270
+ llm: Language model for all agents
271
+ backend: Quantum backend
272
+ tasks: Optional list of task definitions
273
+ process: Crew process type ("sequential" or "hierarchical")
274
+ verbose: Enable verbose output
275
+
276
+ Returns:
277
+ CrewAI Crew with quantum-enhanced agents
278
+
279
+ Example:
280
+ from quantumflow.integrations import create_quantum_crew
281
+
282
+ crew = create_quantum_crew(
283
+ llm=my_llm,
284
+ tasks=[
285
+ {
286
+ "description": "Research quantum computing trends",
287
+ "agent": "researcher",
288
+ "expected_output": "A summary of trends"
289
+ },
290
+ {
291
+ "description": "Optimize resource allocation",
292
+ "agent": "optimizer",
293
+ "expected_output": "Optimal allocation plan"
294
+ }
295
+ ]
296
+ )
297
+ result = crew.kickoff()
298
+ """
299
+ _check_crewai()
300
+
301
+ # Create agents
302
+ researcher = QuantumResearchAgent.create(llm=llm, backend=backend, verbose=verbose)
303
+ optimizer = QuantumOptimizerAgent.create(llm=llm, backend=backend, verbose=verbose)
304
+ analyst = QuantumAnalystAgent.create(llm=llm, backend=backend, verbose=verbose)
305
+
306
+ agents = {
307
+ "researcher": researcher,
308
+ "optimizer": optimizer,
309
+ "analyst": analyst,
310
+ }
311
+
312
+ # Create tasks if provided
313
+ crew_tasks = []
314
+ if tasks:
315
+ for task_def in tasks:
316
+ agent_key = task_def.get("agent", "researcher")
317
+ agent = agents.get(agent_key, researcher)
318
+
319
+ task = Task(
320
+ description=task_def.get("description", ""),
321
+ expected_output=task_def.get("expected_output", "Analysis complete"),
322
+ agent=agent,
323
+ )
324
+ crew_tasks.append(task)
325
+
326
+ # Create crew
327
+ process_type = Process.sequential if process == "sequential" else Process.hierarchical
328
+
329
+ return Crew(
330
+ agents=list(agents.values()),
331
+ tasks=crew_tasks,
332
+ process=process_type,
333
+ verbose=verbose,
334
+ )
335
+
336
+
337
+ # ============== Pre-built Task Templates ==============
338
+
339
+ class QuantumTaskTemplates:
340
+ """Pre-built task templates for common quantum workflows."""
341
+
342
+ @staticmethod
343
+ def research_task(
344
+ topic: str,
345
+ agent: Agent,
346
+ context: Optional[str] = None,
347
+ ) -> Task:
348
+ """Create a research task."""
349
+ _check_crewai()
350
+
351
+ description = f"""
352
+ Research the following topic using quantum-enhanced search: {topic}
353
+
354
+ Steps:
355
+ 1. Use Quantum Search to find relevant information
356
+ 2. Use Quantum Compress to handle large contexts
357
+ 3. Use Quantum Analyze to identify patterns
358
+
359
+ {f'Additional context: {context}' if context else ''}
360
+ """
361
+
362
+ return Task(
363
+ description=description,
364
+ expected_output="Comprehensive research summary with key findings and insights",
365
+ agent=agent,
366
+ )
367
+
368
+ @staticmethod
369
+ def optimization_task(
370
+ problem: str,
371
+ agent: Agent,
372
+ constraints: Optional[Dict] = None,
373
+ ) -> Task:
374
+ """Create an optimization task."""
375
+ _check_crewai()
376
+
377
+ constraints_str = ""
378
+ if constraints:
379
+ constraints_str = "\n".join(f"- {k}: {v}" for k, v in constraints.items())
380
+
381
+ description = f"""
382
+ Solve the following optimization problem using quantum QAOA: {problem}
383
+
384
+ {'Constraints:' + constraints_str if constraints_str else ''}
385
+
386
+ Steps:
387
+ 1. Formulate the problem for QAOA
388
+ 2. Use Quantum Optimize to find optimal solution
389
+ 3. Verify solution quality and constraints
390
+ """
391
+
392
+ return Task(
393
+ description=description,
394
+ expected_output="Optimal solution with quality metrics and constraint satisfaction",
395
+ agent=agent,
396
+ )
397
+
398
+ @staticmethod
399
+ def analysis_task(
400
+ data_description: str,
401
+ agent: Agent,
402
+ analysis_types: Optional[List[str]] = None,
403
+ ) -> Task:
404
+ """Create an analysis task."""
405
+ _check_crewai()
406
+
407
+ types = analysis_types or ["pattern", "anomaly", "correlation"]
408
+ types_str = ", ".join(types)
409
+
410
+ description = f"""
411
+ Analyze the following data using quantum techniques: {data_description}
412
+
413
+ Analysis types to perform: {types_str}
414
+
415
+ Steps:
416
+ 1. Use Quantum Analyze for each analysis type
417
+ 2. Identify key patterns and anomalies
418
+ 3. Summarize findings with quantum-enhanced insights
419
+ """
420
+
421
+ return Task(
422
+ description=description,
423
+ expected_output="Detailed analysis report with patterns, anomalies, and correlations",
424
+ agent=agent,
425
+ )