|
30 | 30 | HARDWARE_PRESETS, |
31 | 31 | get_coupling_map_presets, |
32 | 32 | ) |
33 | | -from qiskit_gym_mcp_server.models import list_loaded_models |
| 33 | +from qiskit_gym_mcp_server.gym_core import get_environment_info |
| 34 | +from qiskit_gym_mcp_server.models import get_model_info, list_loaded_models |
34 | 35 | from qiskit_gym_mcp_server.training import ( |
35 | 36 | get_available_algorithms, |
36 | 37 | get_available_policies, |
| 38 | + get_training_status, |
37 | 39 | list_training_sessions, |
38 | 40 | ) |
39 | 41 |
|
@@ -217,3 +219,72 @@ async def workflows_resource() -> dict[str, Any]: |
217 | 219 | "Increase num_searches (up to 10000) for better synthesis results", |
218 | 220 | ], |
219 | 221 | } |
| 222 | + |
| 223 | + |
| 224 | +################################################## |
| 225 | +## MCP Prompts |
| 226 | +## - https://modelcontextprotocol.io/docs/concepts/prompts |
| 227 | +################################################## |
| 228 | + |
| 229 | + |
| 230 | +@mcp.prompt() |
| 231 | +def train_synthesis_model(env_type: str, num_qubits: str) -> str: |
| 232 | + """Train a reinforcement learning model for quantum circuit synthesis.""" |
| 233 | + return ( |
| 234 | + f"Train an RL model for {env_type} synthesis on {num_qubits} qubits: " |
| 235 | + f"1) Call create_{env_type}_env_tool with appropriate parameters for " |
| 236 | + f"{num_qubits} qubits to create a training environment, " |
| 237 | + "2) Call start_training_tool with the returned env_id and algorithm='ppo', " |
| 238 | + "3) Call get_training_status_tool with the session_id to monitor progress, " |
| 239 | + "4) When training completes, call save_model_tool to persist the trained model." |
| 240 | + ) |
| 241 | + |
| 242 | + |
| 243 | +@mcp.prompt() |
| 244 | +def synthesize_circuit(circuit_type: str) -> str: |
| 245 | + """Synthesize a quantum circuit using a trained RL model.""" |
| 246 | + return ( |
| 247 | + f"Synthesize a {circuit_type} circuit using a trained model: " |
| 248 | + "1) Call list_saved_models_tool to see available models, " |
| 249 | + f"2) Call load_model_tool with a suitable model_name for {circuit_type} synthesis, " |
| 250 | + f"3) Generate a test input using generate_random_{circuit_type}_tool, " |
| 251 | + f"4) Call synthesize_{circuit_type}_tool with the model_id and the generated input, " |
| 252 | + "5) Call convert_qpy_to_qasm3_tool to view the resulting circuit." |
| 253 | + ) |
| 254 | + |
| 255 | + |
| 256 | +@mcp.prompt() |
| 257 | +def explore_hardware_topology(backend_preset: str) -> str: |
| 258 | + """Explore hardware topology and extract subtopologies for training.""" |
| 259 | + return ( |
| 260 | + f"Explore the '{backend_preset}' hardware topology: " |
| 261 | + "1) Read the qiskit-gym://presets/coupling-maps resource to see available presets, " |
| 262 | + f"2) Call extract_subtopologies_tool with preset='{backend_preset}' " |
| 263 | + "to find connected subtopologies, " |
| 264 | + "3) Call list_subtopology_shapes_tool to summarize the shapes found, " |
| 265 | + "4) Create environments for each unique subtopology using create_permutation_env_tool." |
| 266 | + ) |
| 267 | + |
| 268 | + |
| 269 | +################################################## |
| 270 | +## MCP Resource Templates |
| 271 | +## - https://modelcontextprotocol.io/docs/concepts/resources#resource-templates |
| 272 | +################################################## |
| 273 | + |
| 274 | + |
| 275 | +@mcp.resource("qiskit-gym://environments/{env_id}", mime_type="application/json") |
| 276 | +async def environment_info_resource(env_id: str) -> dict[str, Any]: |
| 277 | + """Get detailed information about a specific gym environment.""" |
| 278 | + return await get_environment_info(env_id) |
| 279 | + |
| 280 | + |
| 281 | +@mcp.resource("qiskit-gym://models/{model_name}", mime_type="application/json") |
| 282 | +async def model_info_resource(model_name: str) -> dict[str, Any]: |
| 283 | + """Get information about a specific trained model.""" |
| 284 | + return await get_model_info(model_name=model_name) |
| 285 | + |
| 286 | + |
| 287 | +@mcp.resource("qiskit-gym://training/{session_id}", mime_type="application/json") |
| 288 | +async def training_status_resource(session_id: str) -> dict[str, Any]: |
| 289 | + """Get the status and metrics of a specific training session.""" |
| 290 | + return await get_training_status(session_id) |
0 commit comments