@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { spawn, ChildProcess } from 'child_process';
|
||||
import path from 'path';
|
||||
import * as path from 'path';
|
||||
import { EventEmitter } from 'events';
|
||||
import {
|
||||
PythonCall,
|
||||
@@ -40,7 +40,7 @@ export class PythonBridge extends EventEmitter {
|
||||
|
||||
this.config = {
|
||||
pythonPath: config.pythonPath || process.env.CUDAQ_PYTHON_PATH || 'python3',
|
||||
scriptPath: config.scriptPath || path.join(__dirname, '../../python/cudaq_bridge.py'),
|
||||
scriptPath: config.scriptPath || path.join(process.cwd(), 'python/cudaq_bridge.py'),
|
||||
timeout: config.timeout || 60000,
|
||||
maxMemory: config.maxMemory || 2048
|
||||
};
|
||||
@@ -81,7 +81,7 @@ export class PythonBridge extends EventEmitter {
|
||||
const output = data.toString();
|
||||
this.logger.debug('Python stdout:', output);
|
||||
|
||||
if (!initialized && output.includes('CUDA Quantum Python Bridge')) {
|
||||
if (!initialized && (output.includes('CUDA Quantum Python Bridge') || output.includes('Ready'))) {
|
||||
initialized = true;
|
||||
resolve();
|
||||
}
|
||||
@@ -92,10 +92,20 @@ export class PythonBridge extends EventEmitter {
|
||||
|
||||
this.pythonProcess.stderr?.on('data', (data: Buffer) => {
|
||||
const error = data.toString();
|
||||
this.logger.error('Python stderr:', error);
|
||||
|
||||
if (!initialized) {
|
||||
reject(new Error(`Python process error: ${error}`));
|
||||
// Check if it's just a warning about CUDA Quantum not being available
|
||||
if (error.includes('WARNING') && error.includes('CUDA Quantum not available')) {
|
||||
this.logger.warn('Python warning:', error);
|
||||
// Don't treat this as a fatal error - continue with initialization
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
resolve();
|
||||
}
|
||||
} else {
|
||||
this.logger.error('Python stderr:', error);
|
||||
if (!initialized) {
|
||||
reject(new Error(`Python process error: ${error}`));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
38
src/index.ts
38
src/index.ts
@@ -63,9 +63,9 @@ export class CudaQuantumMCPServer {
|
||||
|
||||
constructor(config: ServerConfig) {
|
||||
this.config = {
|
||||
name: 'cuda-quantum-mcp',
|
||||
version: '1.0.0',
|
||||
...config
|
||||
...config,
|
||||
name: config.name || 'cuda-quantum-mcp',
|
||||
version: config.version || '1.0.0'
|
||||
};
|
||||
|
||||
this.logger = new Logger('MCPServer', {
|
||||
@@ -117,41 +117,41 @@ export class CudaQuantumMCPServer {
|
||||
switch (name) {
|
||||
// Quantum Circuit Tools
|
||||
case 'create_quantum_kernel':
|
||||
return await handleCreateQuantumKernel(args);
|
||||
return await handleCreateQuantumKernel(args as any);
|
||||
case 'apply_quantum_gate':
|
||||
return await handleApplyQuantumGate(args);
|
||||
return await handleApplyQuantumGate(args as any);
|
||||
case 'add_measurement':
|
||||
return await handleAddMeasurement(args);
|
||||
return await handleAddMeasurement(args as any);
|
||||
case 'create_common_circuit':
|
||||
return await handleCreateCommonCircuit(args);
|
||||
return await handleCreateCommonCircuit(args as any);
|
||||
case 'list_quantum_kernels':
|
||||
return await handleListQuantumKernels(args);
|
||||
return await handleListQuantumKernels(args as any);
|
||||
case 'visualize_circuit':
|
||||
return await handleVisualizeCircuit(args);
|
||||
return await handleVisualizeCircuit(args as any);
|
||||
|
||||
// Quantum Execution Tools
|
||||
case 'sample_quantum_circuit':
|
||||
return await handleSampleQuantumCircuit(args);
|
||||
return await handleSampleQuantumCircuit(args as any);
|
||||
case 'observe_hamiltonian':
|
||||
return await handleObserveHamiltonian(args);
|
||||
return await handleObserveHamiltonian(args as any);
|
||||
case 'get_quantum_state':
|
||||
return await handleGetQuantumState(args);
|
||||
return await handleGetQuantumState(args as any);
|
||||
case 'run_quantum_algorithm':
|
||||
return await handleRunQuantumAlgorithm(args);
|
||||
return await handleRunQuantumAlgorithm(args as any);
|
||||
case 'variational_optimization':
|
||||
return await handleVariationalOptimization(args);
|
||||
return await handleVariationalOptimization(args as any);
|
||||
|
||||
// Hardware Backend Tools
|
||||
case 'set_quantum_target':
|
||||
return await handleSetQuantumTarget(args);
|
||||
return await handleSetQuantumTarget(args as any);
|
||||
case 'list_quantum_backends':
|
||||
return await handleListQuantumBackends(args);
|
||||
return await handleListQuantumBackends(args as any);
|
||||
case 'get_platform_info':
|
||||
return await handleGetPlatformInfo(args);
|
||||
return await handleGetPlatformInfo(args as any);
|
||||
case 'test_backend_connectivity':
|
||||
return await handleTestBackendConnectivity(args);
|
||||
return await handleTestBackendConnectivity(args as any);
|
||||
case 'configure_gpu_acceleration':
|
||||
return await handleConfigureGpuAcceleration(args);
|
||||
return await handleConfigureGpuAcceleration(args as any);
|
||||
|
||||
default:
|
||||
throw new Error(`Unknown tool: ${name}`);
|
||||
|
||||
@@ -260,7 +260,7 @@ export async function handleSampleQuantumCircuit(input: any) {
|
||||
let entropy = 0;
|
||||
for (const count of Object.values(counts)) {
|
||||
if ((count as number) > 0) {
|
||||
const p = (count as number) / totalCounts;
|
||||
const p = (count as number) / (totalCounts as number);
|
||||
entropy -= p * Math.log2(p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,6 +311,8 @@ export interface PythonResponse {
|
||||
result?: any;
|
||||
error?: string;
|
||||
traceback?: string;
|
||||
kernels?: string[];
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
// ============================
|
||||
|
||||
Referencia en una nueva incidencia
Block a user