-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_quantum_example.py
More file actions
47 lines (36 loc) · 1.21 KB
/
Copy pathsimple_quantum_example.py
File metadata and controls
47 lines (36 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
"""Simple Quantum Computing Example - No MCP Required"""
import asyncio
from connectors.dwave_quantum_connector import DWaveQuantumConnector
async def solve_optimization_problem():
"""Direct quantum optimization without MCP overhead"""
# 1. Create connector
quantum = DWaveQuantumConnector()
# 2. Connect (you'll need a D-Wave token)
connected = await quantum.connect(
{
"api_token": "your-dwave-token" # Get free at: https://cloud.dwavesys.com/leap/
}
)
if not connected:
print("Failed to connect. Do you have a D-Wave account?")
return
# 3. Solve a simple QUBO problem
# Example: Minimize x0 + x1 - 2*x0*x1
result = await quantum.solve_qubo(
{
"qubo": {
(0, 0): 1, # x0 coefficient
(1, 1): 1, # x1 coefficient
(0, 1): -2, # x0*x1 coefficient
},
"num_reads": 100,
}
)
print(f"Best solution: {result['best_solution']}")
print(f"Best energy: {result['best_energy']}")
# 4. Disconnect
await quantum.disconnect()
# Run it
if __name__ == "__main__":
asyncio.run(solve_optimization_problem())