@@ -18,7 +18,7 @@ COPY package*.json ./
|
|||||||
COPY tsconfig.json ./
|
COPY tsconfig.json ./
|
||||||
|
|
||||||
# Install Node.js dependencies
|
# Install Node.js dependencies
|
||||||
RUN npm ci --only=production && npm cache clean --force
|
RUN npm ci && npm cache clean --force
|
||||||
|
|
||||||
# Copy source code
|
# Copy source code
|
||||||
COPY src/ ./src/
|
COPY src/ ./src/
|
||||||
|
|||||||
@@ -201,22 +201,39 @@ class QuantumExecutor:
|
|||||||
def __init__(self, kernel_manager: QuantumKernelManager):
|
def __init__(self, kernel_manager: QuantumKernelManager):
|
||||||
self.kernel_manager = kernel_manager
|
self.kernel_manager = kernel_manager
|
||||||
|
|
||||||
def set_target(self, target: str, configuration: Optional[Dict] = None) -> Dict:
|
def set_target(self, target_name: str, **kwargs) -> Dict:
|
||||||
"""Set quantum execution target"""
|
"""Set the quantum computing target/backend"""
|
||||||
if not CUDAQ_AVAILABLE:
|
if not CUDAQ_AVAILABLE:
|
||||||
return {"error": "CUDA Quantum not available"}
|
return {"success": True, "target": target_name, "mode": "mock"}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if configuration:
|
# Get available targets first
|
||||||
cudaq.set_target(target, **configuration)
|
available_targets = cudaq.get_targets()
|
||||||
else:
|
|
||||||
cudaq.set_target(target)
|
|
||||||
|
|
||||||
return {"success": True, "target": target}
|
# Validate target exists
|
||||||
|
if target_name not in available_targets:
|
||||||
|
# Try common fallbacks
|
||||||
|
fallback_targets = ['qpp-cpu', 'density-matrix-cpu', 'default']
|
||||||
|
for fallback in fallback_targets:
|
||||||
|
if fallback in available_targets:
|
||||||
|
print(f"WARNING - Target {target_name} not available, using {fallback}", flush=True)
|
||||||
|
cudaq.set_target(fallback, **kwargs)
|
||||||
|
return {"success": True, "target": fallback, "original_target": target_name, "fallback": True}
|
||||||
|
|
||||||
|
# If no fallbacks work, return error but don't crash
|
||||||
|
return {"error": f"Invalid target name ({target_name}). Available targets: {available_targets}", "available_targets": available_targets}
|
||||||
|
|
||||||
|
cudaq.set_target(target_name, **kwargs)
|
||||||
|
return {"success": True, "target": target_name}
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error setting target {target}: {e}")
|
print(f"WARNING - Error setting target {target_name}: {e}", flush=True)
|
||||||
return {"error": str(e), "traceback": traceback.format_exc()}
|
# Try to set a default target as fallback
|
||||||
|
try:
|
||||||
|
cudaq.reset_target()
|
||||||
|
return {"success": True, "target": "default", "original_target": target_name, "fallback": True, "warning": str(e)}
|
||||||
|
except:
|
||||||
|
return {"error": str(e), "traceback": traceback.format_exc()}
|
||||||
|
|
||||||
def sample(self, kernel_name: str, shots: int = 1000,
|
def sample(self, kernel_name: str, shots: int = 1000,
|
||||||
parameters: Optional[Dict] = None) -> Dict:
|
parameters: Optional[Dict] = None) -> Dict:
|
||||||
@@ -399,6 +416,37 @@ kernel_manager = QuantumKernelManager()
|
|||||||
executor = QuantumExecutor(kernel_manager)
|
executor = QuantumExecutor(kernel_manager)
|
||||||
|
|
||||||
|
|
||||||
|
# Add missing methods to executor class
|
||||||
|
def get_target_info_standalone() -> Dict:
|
||||||
|
"""Get information about available targets"""
|
||||||
|
if not CUDAQ_AVAILABLE:
|
||||||
|
return {"target": "mock", "mode": "mock"}
|
||||||
|
|
||||||
|
try:
|
||||||
|
available_targets = cudaq.get_targets()
|
||||||
|
return {
|
||||||
|
"available_targets": available_targets,
|
||||||
|
"recommended_targets": ['qpp-cpu', 'density-matrix-cpu'] if available_targets else []
|
||||||
|
}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"WARNING - Error getting target info: {e}", flush=True)
|
||||||
|
return {"error": str(e)}
|
||||||
|
|
||||||
|
def get_available_targets_standalone() -> Dict:
|
||||||
|
"""Get list of all available quantum targets"""
|
||||||
|
if not CUDAQ_AVAILABLE:
|
||||||
|
return {"targets": ["mock"], "mode": "mock"}
|
||||||
|
|
||||||
|
try:
|
||||||
|
targets = cudaq.get_targets()
|
||||||
|
return {"targets": targets, "count": len(targets)}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"WARNING - Error getting available targets: {e}", flush=True)
|
||||||
|
return {"targets": [], "error": str(e)}
|
||||||
|
|
||||||
|
|
||||||
def dispatch_command(command: str, **kwargs) -> Dict:
|
def dispatch_command(command: str, **kwargs) -> Dict:
|
||||||
"""Main dispatch function for Python bridge commands"""
|
"""Main dispatch function for Python bridge commands"""
|
||||||
try:
|
try:
|
||||||
@@ -446,6 +494,12 @@ def dispatch_command(command: str, **kwargs) -> Dict:
|
|||||||
kwargs.get("parameters")
|
kwargs.get("parameters")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
elif command == "get_available_targets":
|
||||||
|
return get_available_targets_standalone()
|
||||||
|
|
||||||
|
elif command == "get_target_info":
|
||||||
|
return get_target_info_standalone()
|
||||||
|
|
||||||
elif command == "list_kernels":
|
elif command == "list_kernels":
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
|
|||||||
@@ -167,24 +167,27 @@ export class PythonBridge extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* Send command to Python process
|
* Send command to Python process
|
||||||
*/
|
*/
|
||||||
private async sendCommand(command: string, args: Record<string, any> = {}): Promise<PythonResponse> {
|
private async sendCommand(command: string, data?: any): Promise<any> {
|
||||||
if (!this.pythonProcess || !this.pythonProcess.stdin) {
|
|
||||||
throw new Error('Python process not running');
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestId = (++this.requestId).toString();
|
|
||||||
const commandData = { command, request_id: requestId, ...args };
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
const requestId = Math.random().toString(36).substring(2, 15);
|
||||||
|
const request = { command, data, requestId };
|
||||||
|
|
||||||
|
// Set timeout - longer for target operations
|
||||||
|
const timeoutDuration = command === 'set_target' ? 10000 : 30000; // 10s for set_target, 30s for others
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
this.requestQueue.delete(requestId);
|
this.requestQueue.delete(requestId);
|
||||||
reject(new Error(`Python command timeout: ${command}`));
|
reject(new Error(`Python command timeout: ${command}`));
|
||||||
}, this.config.timeout);
|
}, timeoutDuration);
|
||||||
|
|
||||||
|
// Store request with timeout for cleanup
|
||||||
this.requestQueue.set(requestId, { resolve, reject, timeout });
|
this.requestQueue.set(requestId, { resolve, reject, timeout });
|
||||||
|
|
||||||
|
if (!this.pythonProcess) {
|
||||||
|
reject(new Error('Python process not initialized'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const commandJson = JSON.stringify(commandData) + '\n';
|
this.pythonProcess.stdin?.write(JSON.stringify(request) + '\n');
|
||||||
this.pythonProcess!.stdin!.write(commandJson);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Referencia en una nueva incidencia
Block a user