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.
- api/__init__.py +1 -0
- api/auth.py +208 -0
- api/main.py +403 -0
- api/models.py +137 -0
- api/routes/__init__.py +1 -0
- api/routes/auth_routes.py +234 -0
- api/routes/teleport_routes.py +415 -0
- db/__init__.py +15 -0
- db/crud.py +319 -0
- db/database.py +93 -0
- db/models.py +197 -0
- quantumflow/__init__.py +47 -0
- quantumflow/algorithms/__init__.py +48 -0
- quantumflow/algorithms/compression/__init__.py +7 -0
- quantumflow/algorithms/compression/amplitude_amplification.py +189 -0
- quantumflow/algorithms/compression/qft_compression.py +133 -0
- quantumflow/algorithms/compression/token_compression.py +261 -0
- quantumflow/algorithms/cryptography/__init__.py +6 -0
- quantumflow/algorithms/cryptography/qkd.py +205 -0
- quantumflow/algorithms/cryptography/qrng.py +231 -0
- quantumflow/algorithms/machine_learning/__init__.py +7 -0
- quantumflow/algorithms/machine_learning/qnn.py +276 -0
- quantumflow/algorithms/machine_learning/qsvm.py +249 -0
- quantumflow/algorithms/machine_learning/vqe.py +229 -0
- quantumflow/algorithms/optimization/__init__.py +7 -0
- quantumflow/algorithms/optimization/grover.py +223 -0
- quantumflow/algorithms/optimization/qaoa.py +251 -0
- quantumflow/algorithms/optimization/quantum_annealing.py +237 -0
- quantumflow/algorithms/utility/__init__.py +6 -0
- quantumflow/algorithms/utility/circuit_optimizer.py +194 -0
- quantumflow/algorithms/utility/error_correction.py +330 -0
- quantumflow/api/__init__.py +1 -0
- quantumflow/api/routes/__init__.py +4 -0
- quantumflow/api/routes/billing_routes.py +520 -0
- quantumflow/backends/__init__.py +33 -0
- quantumflow/backends/base_backend.py +184 -0
- quantumflow/backends/braket_backend.py +345 -0
- quantumflow/backends/ibm_backend.py +112 -0
- quantumflow/backends/simulator_backend.py +86 -0
- quantumflow/billing/__init__.py +25 -0
- quantumflow/billing/models.py +126 -0
- quantumflow/billing/stripe_service.py +619 -0
- quantumflow/core/__init__.py +12 -0
- quantumflow/core/entanglement.py +164 -0
- quantumflow/core/memory.py +147 -0
- quantumflow/core/quantum_backprop.py +394 -0
- quantumflow/core/quantum_compressor.py +309 -0
- quantumflow/core/teleportation.py +386 -0
- quantumflow/integrations/__init__.py +107 -0
- quantumflow/integrations/autogen_tools.py +501 -0
- quantumflow/integrations/crewai_agents.py +425 -0
- quantumflow/integrations/crewai_tools.py +407 -0
- quantumflow/integrations/langchain_memory.py +385 -0
- quantumflow/integrations/langchain_tools.py +366 -0
- quantumflow/integrations/mcp_server.py +575 -0
- quantumflow_sdk-0.1.0.dist-info/METADATA +190 -0
- quantumflow_sdk-0.1.0.dist-info/RECORD +60 -0
- quantumflow_sdk-0.1.0.dist-info/WHEEL +5 -0
- quantumflow_sdk-0.1.0.dist-info/entry_points.txt +2 -0
- quantumflow_sdk-0.1.0.dist-info/top_level.txt +3 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""
|
|
2
|
+
QuantumFlow Integrations.
|
|
3
|
+
|
|
4
|
+
Provides integration with popular AI agent frameworks:
|
|
5
|
+
- LangChain: Tools, Memory, and Chains
|
|
6
|
+
- CrewAI: Tools and Agents
|
|
7
|
+
- AutoGen: Agents and Function Tools
|
|
8
|
+
- MCP: Model Context Protocol Server
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
# LangChain Integration
|
|
12
|
+
from quantumflow.integrations.langchain_tools import (
|
|
13
|
+
QuantumCompressTool,
|
|
14
|
+
QuantumGradientTool,
|
|
15
|
+
QuantumMemoryTool,
|
|
16
|
+
QuantumEntangleTool,
|
|
17
|
+
QuantumSearchTool,
|
|
18
|
+
get_quantum_toolkit,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
from quantumflow.integrations.langchain_memory import (
|
|
22
|
+
QuantumChatMemory,
|
|
23
|
+
QuantumVectorStore,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
# CrewAI Integration
|
|
27
|
+
from quantumflow.integrations.crewai_tools import (
|
|
28
|
+
QuantumCompressCrewTool,
|
|
29
|
+
QuantumOptimizeCrewTool,
|
|
30
|
+
QuantumAnalyzeCrewTool,
|
|
31
|
+
QuantumSearchCrewTool,
|
|
32
|
+
get_quantum_crew_tools,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
from quantumflow.integrations.crewai_agents import (
|
|
36
|
+
QuantumResearchAgent,
|
|
37
|
+
QuantumOptimizerAgent,
|
|
38
|
+
QuantumAnalystAgent,
|
|
39
|
+
create_quantum_crew,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# AutoGen Integration
|
|
43
|
+
from quantumflow.integrations.autogen_tools import (
|
|
44
|
+
quantum_compress,
|
|
45
|
+
quantum_gradient,
|
|
46
|
+
quantum_memory_store,
|
|
47
|
+
quantum_memory_retrieve,
|
|
48
|
+
quantum_search,
|
|
49
|
+
quantum_optimize,
|
|
50
|
+
quantum_entangle,
|
|
51
|
+
get_quantum_functions,
|
|
52
|
+
register_quantum_functions,
|
|
53
|
+
create_quantum_assistant,
|
|
54
|
+
create_quantum_researcher,
|
|
55
|
+
create_quantum_optimizer,
|
|
56
|
+
create_quantum_group_chat,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
# MCP Integration
|
|
60
|
+
from quantumflow.integrations.mcp_server import (
|
|
61
|
+
QuantumMCPServer,
|
|
62
|
+
create_mcp_server,
|
|
63
|
+
get_mcp_config,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
__all__ = [
|
|
67
|
+
# LangChain Tools
|
|
68
|
+
"QuantumCompressTool",
|
|
69
|
+
"QuantumGradientTool",
|
|
70
|
+
"QuantumMemoryTool",
|
|
71
|
+
"QuantumEntangleTool",
|
|
72
|
+
"QuantumSearchTool",
|
|
73
|
+
"get_quantum_toolkit",
|
|
74
|
+
# LangChain Memory
|
|
75
|
+
"QuantumChatMemory",
|
|
76
|
+
"QuantumVectorStore",
|
|
77
|
+
# CrewAI Tools
|
|
78
|
+
"QuantumCompressCrewTool",
|
|
79
|
+
"QuantumOptimizeCrewTool",
|
|
80
|
+
"QuantumAnalyzeCrewTool",
|
|
81
|
+
"QuantumSearchCrewTool",
|
|
82
|
+
"get_quantum_crew_tools",
|
|
83
|
+
# CrewAI Agents
|
|
84
|
+
"QuantumResearchAgent",
|
|
85
|
+
"QuantumOptimizerAgent",
|
|
86
|
+
"QuantumAnalystAgent",
|
|
87
|
+
"create_quantum_crew",
|
|
88
|
+
# AutoGen Functions
|
|
89
|
+
"quantum_compress",
|
|
90
|
+
"quantum_gradient",
|
|
91
|
+
"quantum_memory_store",
|
|
92
|
+
"quantum_memory_retrieve",
|
|
93
|
+
"quantum_search",
|
|
94
|
+
"quantum_optimize",
|
|
95
|
+
"quantum_entangle",
|
|
96
|
+
"get_quantum_functions",
|
|
97
|
+
"register_quantum_functions",
|
|
98
|
+
# AutoGen Agents
|
|
99
|
+
"create_quantum_assistant",
|
|
100
|
+
"create_quantum_researcher",
|
|
101
|
+
"create_quantum_optimizer",
|
|
102
|
+
"create_quantum_group_chat",
|
|
103
|
+
# MCP Server
|
|
104
|
+
"QuantumMCPServer",
|
|
105
|
+
"create_mcp_server",
|
|
106
|
+
"get_mcp_config",
|
|
107
|
+
]
|
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AutoGen Integration for QuantumFlow.
|
|
3
|
+
|
|
4
|
+
Provides quantum-enhanced agents and tools for Microsoft AutoGen.
|
|
5
|
+
|
|
6
|
+
Features:
|
|
7
|
+
- Quantum function tools for agents
|
|
8
|
+
- Pre-configured quantum assistant agents
|
|
9
|
+
- Group chat with quantum capabilities
|
|
10
|
+
|
|
11
|
+
Requirements:
|
|
12
|
+
pip install pyautogen
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from typing import Any, Dict, List, Optional, Callable, Annotated
|
|
16
|
+
import json
|
|
17
|
+
import numpy as np
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
from autogen import (
|
|
21
|
+
AssistantAgent,
|
|
22
|
+
UserProxyAgent,
|
|
23
|
+
ConversableAgent,
|
|
24
|
+
GroupChat,
|
|
25
|
+
GroupChatManager,
|
|
26
|
+
register_function,
|
|
27
|
+
)
|
|
28
|
+
AUTOGEN_AVAILABLE = True
|
|
29
|
+
except ImportError:
|
|
30
|
+
AUTOGEN_AVAILABLE = False
|
|
31
|
+
# Dummy classes
|
|
32
|
+
class AssistantAgent:
|
|
33
|
+
pass
|
|
34
|
+
class UserProxyAgent:
|
|
35
|
+
pass
|
|
36
|
+
class ConversableAgent:
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
from quantumflow.core.quantum_compressor import QuantumCompressor
|
|
40
|
+
from quantumflow.core.quantum_backprop import QuantumBackprop
|
|
41
|
+
from quantumflow.core.memory import QuantumMemory
|
|
42
|
+
from quantumflow.core.entanglement import Entangler
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _check_autogen():
|
|
46
|
+
"""Check if AutoGen is available."""
|
|
47
|
+
if not AUTOGEN_AVAILABLE:
|
|
48
|
+
raise ImportError(
|
|
49
|
+
"AutoGen is not installed. "
|
|
50
|
+
"Install it with: pip install pyautogen"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# ============== Quantum Function Tools ==============
|
|
55
|
+
|
|
56
|
+
# Global instances for tools
|
|
57
|
+
_compressor: Optional[QuantumCompressor] = None
|
|
58
|
+
_backprop: Optional[QuantumBackprop] = None
|
|
59
|
+
_memory: Optional[QuantumMemory] = None
|
|
60
|
+
_entangler: Optional[Entangler] = None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _init_quantum_components(backend: str = "simulator"):
|
|
64
|
+
"""Initialize quantum components."""
|
|
65
|
+
global _compressor, _backprop, _memory, _entangler
|
|
66
|
+
if _compressor is None:
|
|
67
|
+
_compressor = QuantumCompressor(backend=backend)
|
|
68
|
+
if _backprop is None:
|
|
69
|
+
_backprop = QuantumBackprop(backend=backend)
|
|
70
|
+
if _memory is None:
|
|
71
|
+
_memory = QuantumMemory(backend=backend)
|
|
72
|
+
if _entangler is None:
|
|
73
|
+
_entangler = Entangler(backend=backend)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def quantum_compress(
|
|
77
|
+
text: Annotated[str, "Text to compress using quantum encoding"],
|
|
78
|
+
compression_level: Annotated[int, "Compression level (1-3)"] = 1,
|
|
79
|
+
) -> str:
|
|
80
|
+
"""
|
|
81
|
+
Compress text using quantum amplitude encoding.
|
|
82
|
+
Achieves up to 53% token reduction.
|
|
83
|
+
"""
|
|
84
|
+
_init_quantum_components()
|
|
85
|
+
|
|
86
|
+
words = text.split()
|
|
87
|
+
if len(words) < 2:
|
|
88
|
+
return f"Text too short to compress ({len(words)} words)"
|
|
89
|
+
|
|
90
|
+
tokens = [hash(w) % 10000 for w in words]
|
|
91
|
+
|
|
92
|
+
result = _compressor.compress(
|
|
93
|
+
tokens=tokens,
|
|
94
|
+
compression_level=compression_level,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
return json.dumps({
|
|
98
|
+
"input_tokens": result.input_token_count,
|
|
99
|
+
"output_qubits": result.n_qubits,
|
|
100
|
+
"tokens_saved": result.tokens_saved,
|
|
101
|
+
"compression_ratio": round(result.compression_ratio, 2),
|
|
102
|
+
"reduction_percent": round(result.compression_percentage, 1),
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def quantum_gradient(
|
|
107
|
+
input_values: Annotated[List[float], "Input state values"],
|
|
108
|
+
target_values: Annotated[List[float], "Target state values"],
|
|
109
|
+
weights: Annotated[List[float], "Current weight values"],
|
|
110
|
+
) -> str:
|
|
111
|
+
"""
|
|
112
|
+
Compute gradients using quantum teleportation protocol.
|
|
113
|
+
Achieves 97.78% similarity with classical gradients.
|
|
114
|
+
"""
|
|
115
|
+
_init_quantum_components()
|
|
116
|
+
|
|
117
|
+
result = _backprop.compute_gradient(
|
|
118
|
+
input_state=np.array(input_values),
|
|
119
|
+
target_state=np.array(target_values),
|
|
120
|
+
weights=np.array(weights),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
return json.dumps({
|
|
124
|
+
"gradients": result.gradients.tolist(),
|
|
125
|
+
"direction": result.gradient_direction,
|
|
126
|
+
"magnitude": round(result.gradient_magnitude, 4),
|
|
127
|
+
"classical_similarity": round(abs(result.similarity), 4),
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def quantum_memory_store(
|
|
132
|
+
key: Annotated[str, "Memory key"],
|
|
133
|
+
values: Annotated[List[float], "Values to store"],
|
|
134
|
+
compress: Annotated[bool, "Whether to compress"] = True,
|
|
135
|
+
) -> str:
|
|
136
|
+
"""
|
|
137
|
+
Store data in quantum memory with O(log n) complexity.
|
|
138
|
+
"""
|
|
139
|
+
_init_quantum_components()
|
|
140
|
+
|
|
141
|
+
slot = _memory.store(key, values, compress=compress)
|
|
142
|
+
|
|
143
|
+
return json.dumps({
|
|
144
|
+
"key": key,
|
|
145
|
+
"stored_count": len(values),
|
|
146
|
+
"qubits_used": slot.compressed.n_qubits if slot.compressed else None,
|
|
147
|
+
"compression_ratio": round(slot.compressed.compression_ratio, 2) if slot.compressed else None,
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def quantum_memory_retrieve(
|
|
152
|
+
key: Annotated[str, "Memory key to retrieve"],
|
|
153
|
+
) -> str:
|
|
154
|
+
"""
|
|
155
|
+
Retrieve data from quantum memory.
|
|
156
|
+
"""
|
|
157
|
+
_init_quantum_components()
|
|
158
|
+
|
|
159
|
+
try:
|
|
160
|
+
values = _memory.retrieve(key)
|
|
161
|
+
return json.dumps({
|
|
162
|
+
"key": key,
|
|
163
|
+
"values": values[:10] if len(values) > 10 else values,
|
|
164
|
+
"total_values": len(values),
|
|
165
|
+
})
|
|
166
|
+
except KeyError:
|
|
167
|
+
return json.dumps({"error": f"Key '{key}' not found"})
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def quantum_search(
|
|
171
|
+
query: Annotated[str, "Search query"],
|
|
172
|
+
database: Annotated[List[str], "List of items to search"],
|
|
173
|
+
) -> str:
|
|
174
|
+
"""
|
|
175
|
+
Search database using Grover's quantum algorithm.
|
|
176
|
+
Provides quadratic speedup: O(sqrt(N)) vs O(N).
|
|
177
|
+
"""
|
|
178
|
+
import math
|
|
179
|
+
from quantumflow.algorithms.optimization import GroverSearch
|
|
180
|
+
|
|
181
|
+
_init_quantum_components()
|
|
182
|
+
|
|
183
|
+
query_lower = query.lower()
|
|
184
|
+
marked_indices = [i for i, item in enumerate(database) if query_lower in str(item).lower()]
|
|
185
|
+
|
|
186
|
+
if not marked_indices:
|
|
187
|
+
return json.dumps({
|
|
188
|
+
"query": query,
|
|
189
|
+
"matches": [],
|
|
190
|
+
"message": "No matches found",
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
n_qubits = max(2, math.ceil(math.log2(len(database))))
|
|
194
|
+
grover = GroverSearch(backend="simulator")
|
|
195
|
+
result = grover.search(n_qubits=n_qubits, marked_states=marked_indices)
|
|
196
|
+
|
|
197
|
+
matches = [database[i] for i in marked_indices]
|
|
198
|
+
|
|
199
|
+
return json.dumps({
|
|
200
|
+
"query": query,
|
|
201
|
+
"matches": matches[:5],
|
|
202
|
+
"total_matches": len(matches),
|
|
203
|
+
"quantum_iterations": result.iterations,
|
|
204
|
+
"success_probability": round(result.probability, 4),
|
|
205
|
+
"speedup": round(len(database) / max(1, result.iterations), 1),
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def quantum_optimize(
|
|
210
|
+
problem_type: Annotated[str, "Problem type: 'maxcut' or 'portfolio'"],
|
|
211
|
+
problem_data: Annotated[Dict, "Problem-specific data"],
|
|
212
|
+
) -> str:
|
|
213
|
+
"""
|
|
214
|
+
Solve optimization problems using QAOA quantum algorithm.
|
|
215
|
+
Supports MaxCut and portfolio optimization.
|
|
216
|
+
"""
|
|
217
|
+
from quantumflow.algorithms.optimization import QAOA
|
|
218
|
+
|
|
219
|
+
_init_quantum_components()
|
|
220
|
+
|
|
221
|
+
qaoa = QAOA(backend="simulator", p=1)
|
|
222
|
+
|
|
223
|
+
if problem_type == "maxcut":
|
|
224
|
+
edges = problem_data.get("edges", [(0, 1), (1, 2), (2, 0)])
|
|
225
|
+
edges = [tuple(e) if isinstance(e, list) else e for e in edges]
|
|
226
|
+
n_nodes = problem_data.get("n_nodes", 3)
|
|
227
|
+
|
|
228
|
+
result = qaoa.maxcut(edges, n_nodes, max_iterations=20)
|
|
229
|
+
|
|
230
|
+
return json.dumps({
|
|
231
|
+
"problem": "maxcut",
|
|
232
|
+
"solution": result.best_solution,
|
|
233
|
+
"cost": round(result.best_cost, 2),
|
|
234
|
+
"iterations": result.n_iterations,
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
elif problem_type == "portfolio":
|
|
238
|
+
returns = np.array(problem_data.get("returns", [0.1, 0.05, 0.15]))
|
|
239
|
+
covariance = np.array(problem_data.get("covariance", [[0.1, 0.02], [0.02, 0.05]]))
|
|
240
|
+
risk_factor = problem_data.get("risk_factor", 0.5)
|
|
241
|
+
|
|
242
|
+
n_assets = len(returns)
|
|
243
|
+
Q = np.zeros((n_assets, n_assets))
|
|
244
|
+
for i in range(n_assets):
|
|
245
|
+
Q[i, i] = -returns[i] + risk_factor * covariance[i, i]
|
|
246
|
+
for j in range(i + 1, n_assets):
|
|
247
|
+
if i < covariance.shape[0] and j < covariance.shape[1]:
|
|
248
|
+
Q[i, j] = risk_factor * covariance[i, j]
|
|
249
|
+
|
|
250
|
+
result = qaoa.optimize_qubo(Q, max_iterations=20)
|
|
251
|
+
|
|
252
|
+
return json.dumps({
|
|
253
|
+
"problem": "portfolio",
|
|
254
|
+
"allocation": result.best_solution,
|
|
255
|
+
"cost": round(result.best_cost, 4),
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
return json.dumps({"error": f"Unknown problem type: {problem_type}"})
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def quantum_entangle(
|
|
262
|
+
contexts: Annotated[List[str], "List of contexts to entangle"],
|
|
263
|
+
) -> str:
|
|
264
|
+
"""
|
|
265
|
+
Create quantum entanglement between contexts.
|
|
266
|
+
Creates Bell pairs (2 contexts) or GHZ states (3+ contexts).
|
|
267
|
+
"""
|
|
268
|
+
_init_quantum_components()
|
|
269
|
+
|
|
270
|
+
if len(contexts) < 2:
|
|
271
|
+
return json.dumps({"error": "Need at least 2 contexts"})
|
|
272
|
+
|
|
273
|
+
# Convert string contexts to numeric representations
|
|
274
|
+
numeric_contexts = []
|
|
275
|
+
for ctx in contexts:
|
|
276
|
+
values = [ord(c) / 255.0 for c in ctx[:10]]
|
|
277
|
+
if len(values) < 2:
|
|
278
|
+
values = values + [0.5] * (2 - len(values))
|
|
279
|
+
numeric_contexts.append(values)
|
|
280
|
+
|
|
281
|
+
if len(contexts) == 2:
|
|
282
|
+
state = _entangler.entangle_contexts(numeric_contexts[0], numeric_contexts[1])
|
|
283
|
+
else:
|
|
284
|
+
state = _entangler.create_ghz_state(len(contexts))
|
|
285
|
+
|
|
286
|
+
return json.dumps({
|
|
287
|
+
"n_qubits": state.n_qubits,
|
|
288
|
+
"n_parties": state.n_parties,
|
|
289
|
+
"entropy": round(state.entropy, 4),
|
|
290
|
+
"maximally_entangled": state.is_maximally_entangled,
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
# ============== Tool Registration ==============
|
|
295
|
+
|
|
296
|
+
def get_quantum_functions() -> List[Callable]:
|
|
297
|
+
"""
|
|
298
|
+
Get all quantum functions for AutoGen registration.
|
|
299
|
+
|
|
300
|
+
Returns:
|
|
301
|
+
List of quantum function tools
|
|
302
|
+
"""
|
|
303
|
+
_check_autogen()
|
|
304
|
+
|
|
305
|
+
return [
|
|
306
|
+
quantum_compress,
|
|
307
|
+
quantum_gradient,
|
|
308
|
+
quantum_memory_store,
|
|
309
|
+
quantum_memory_retrieve,
|
|
310
|
+
quantum_search,
|
|
311
|
+
quantum_optimize,
|
|
312
|
+
quantum_entangle,
|
|
313
|
+
]
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def register_quantum_functions(
|
|
317
|
+
assistant: AssistantAgent,
|
|
318
|
+
user_proxy: UserProxyAgent,
|
|
319
|
+
) -> None:
|
|
320
|
+
"""
|
|
321
|
+
Register all quantum functions with AutoGen agents.
|
|
322
|
+
|
|
323
|
+
Args:
|
|
324
|
+
assistant: The assistant agent
|
|
325
|
+
user_proxy: The user proxy agent
|
|
326
|
+
|
|
327
|
+
Example:
|
|
328
|
+
assistant = AssistantAgent("assistant", llm_config=config)
|
|
329
|
+
user_proxy = UserProxyAgent("user")
|
|
330
|
+
register_quantum_functions(assistant, user_proxy)
|
|
331
|
+
"""
|
|
332
|
+
_check_autogen()
|
|
333
|
+
|
|
334
|
+
functions = get_quantum_functions()
|
|
335
|
+
|
|
336
|
+
for func in functions:
|
|
337
|
+
register_function(
|
|
338
|
+
func,
|
|
339
|
+
caller=assistant,
|
|
340
|
+
executor=user_proxy,
|
|
341
|
+
description=func.__doc__,
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
# ============== Pre-configured Agents ==============
|
|
346
|
+
|
|
347
|
+
def create_quantum_assistant(
|
|
348
|
+
name: str = "QuantumAssistant",
|
|
349
|
+
llm_config: Optional[Dict] = None,
|
|
350
|
+
system_message: Optional[str] = None,
|
|
351
|
+
) -> AssistantAgent:
|
|
352
|
+
"""
|
|
353
|
+
Create a quantum-enhanced assistant agent.
|
|
354
|
+
|
|
355
|
+
Args:
|
|
356
|
+
name: Agent name
|
|
357
|
+
llm_config: LLM configuration
|
|
358
|
+
system_message: Custom system message
|
|
359
|
+
|
|
360
|
+
Returns:
|
|
361
|
+
Configured AssistantAgent with quantum capabilities
|
|
362
|
+
"""
|
|
363
|
+
_check_autogen()
|
|
364
|
+
|
|
365
|
+
default_message = """You are a quantum computing assistant with access to quantum tools.
|
|
366
|
+
|
|
367
|
+
Available quantum capabilities:
|
|
368
|
+
1. quantum_compress - Compress text using quantum amplitude encoding (53% reduction)
|
|
369
|
+
2. quantum_gradient - Compute gradients using quantum teleportation
|
|
370
|
+
3. quantum_memory_store/retrieve - Store/retrieve data with O(log n) complexity
|
|
371
|
+
4. quantum_search - Search with Grover's algorithm (quadratic speedup)
|
|
372
|
+
5. quantum_optimize - Solve optimization problems with QAOA
|
|
373
|
+
6. quantum_entangle - Create entangled states between contexts
|
|
374
|
+
|
|
375
|
+
Use these tools when they can provide quantum advantage for the task.
|
|
376
|
+
Always explain the quantum benefit when using a tool."""
|
|
377
|
+
|
|
378
|
+
return AssistantAgent(
|
|
379
|
+
name=name,
|
|
380
|
+
llm_config=llm_config,
|
|
381
|
+
system_message=system_message or default_message,
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def create_quantum_researcher(
|
|
386
|
+
name: str = "QuantumResearcher",
|
|
387
|
+
llm_config: Optional[Dict] = None,
|
|
388
|
+
) -> AssistantAgent:
|
|
389
|
+
"""Create a quantum research specialist agent."""
|
|
390
|
+
_check_autogen()
|
|
391
|
+
|
|
392
|
+
system_message = """You are a quantum research specialist.
|
|
393
|
+
|
|
394
|
+
Your expertise:
|
|
395
|
+
- Using quantum_search for fast information retrieval
|
|
396
|
+
- Using quantum_compress to handle large research contexts
|
|
397
|
+
- Analyzing patterns in research data
|
|
398
|
+
|
|
399
|
+
When researching topics:
|
|
400
|
+
1. Use quantum_search to find relevant information quickly
|
|
401
|
+
2. Compress large contexts with quantum_compress
|
|
402
|
+
3. Identify patterns and correlations
|
|
403
|
+
|
|
404
|
+
Always cite quantum speedups achieved."""
|
|
405
|
+
|
|
406
|
+
return AssistantAgent(
|
|
407
|
+
name=name,
|
|
408
|
+
llm_config=llm_config,
|
|
409
|
+
system_message=system_message,
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
def create_quantum_optimizer(
|
|
414
|
+
name: str = "QuantumOptimizer",
|
|
415
|
+
llm_config: Optional[Dict] = None,
|
|
416
|
+
) -> AssistantAgent:
|
|
417
|
+
"""Create a quantum optimization specialist agent."""
|
|
418
|
+
_check_autogen()
|
|
419
|
+
|
|
420
|
+
system_message = """You are a quantum optimization specialist.
|
|
421
|
+
|
|
422
|
+
Your expertise:
|
|
423
|
+
- Solving MaxCut problems with QAOA
|
|
424
|
+
- Portfolio optimization using quantum algorithms
|
|
425
|
+
- Combinatorial optimization problems
|
|
426
|
+
|
|
427
|
+
When optimizing:
|
|
428
|
+
1. Identify the problem type (maxcut, portfolio, etc.)
|
|
429
|
+
2. Use quantum_optimize with appropriate parameters
|
|
430
|
+
3. Interpret results and explain quantum advantage
|
|
431
|
+
|
|
432
|
+
For MaxCut: provide edges and n_nodes
|
|
433
|
+
For Portfolio: provide returns, covariance, risk_factor"""
|
|
434
|
+
|
|
435
|
+
return AssistantAgent(
|
|
436
|
+
name=name,
|
|
437
|
+
llm_config=llm_config,
|
|
438
|
+
system_message=system_message,
|
|
439
|
+
)
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
def create_quantum_group_chat(
|
|
443
|
+
llm_config: Dict,
|
|
444
|
+
user_proxy: Optional[UserProxyAgent] = None,
|
|
445
|
+
max_round: int = 10,
|
|
446
|
+
) -> tuple:
|
|
447
|
+
"""
|
|
448
|
+
Create a group chat with quantum-enhanced agents.
|
|
449
|
+
|
|
450
|
+
Args:
|
|
451
|
+
llm_config: LLM configuration for agents
|
|
452
|
+
user_proxy: Optional user proxy (created if None)
|
|
453
|
+
max_round: Maximum conversation rounds
|
|
454
|
+
|
|
455
|
+
Returns:
|
|
456
|
+
Tuple of (GroupChatManager, agents_dict)
|
|
457
|
+
|
|
458
|
+
Example:
|
|
459
|
+
manager, agents = create_quantum_group_chat(llm_config)
|
|
460
|
+
agents["user"].initiate_chat(manager, message="Optimize this portfolio...")
|
|
461
|
+
"""
|
|
462
|
+
_check_autogen()
|
|
463
|
+
|
|
464
|
+
# Create user proxy if not provided
|
|
465
|
+
if user_proxy is None:
|
|
466
|
+
user_proxy = UserProxyAgent(
|
|
467
|
+
name="User",
|
|
468
|
+
human_input_mode="NEVER",
|
|
469
|
+
code_execution_config={"use_docker": False},
|
|
470
|
+
)
|
|
471
|
+
|
|
472
|
+
# Create specialized agents
|
|
473
|
+
assistant = create_quantum_assistant(llm_config=llm_config)
|
|
474
|
+
researcher = create_quantum_researcher(llm_config=llm_config)
|
|
475
|
+
optimizer = create_quantum_optimizer(llm_config=llm_config)
|
|
476
|
+
|
|
477
|
+
# Register functions with all agents
|
|
478
|
+
for agent in [assistant, researcher, optimizer]:
|
|
479
|
+
register_quantum_functions(agent, user_proxy)
|
|
480
|
+
|
|
481
|
+
# Create group chat
|
|
482
|
+
agents = [user_proxy, assistant, researcher, optimizer]
|
|
483
|
+
|
|
484
|
+
group_chat = GroupChat(
|
|
485
|
+
agents=agents,
|
|
486
|
+
messages=[],
|
|
487
|
+
max_round=max_round,
|
|
488
|
+
speaker_selection_method="auto",
|
|
489
|
+
)
|
|
490
|
+
|
|
491
|
+
manager = GroupChatManager(
|
|
492
|
+
groupchat=group_chat,
|
|
493
|
+
llm_config=llm_config,
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
return manager, {
|
|
497
|
+
"user": user_proxy,
|
|
498
|
+
"assistant": assistant,
|
|
499
|
+
"researcher": researcher,
|
|
500
|
+
"optimizer": optimizer,
|
|
501
|
+
}
|