Skip to main content
Glama

run_simulation

Execute a stored quantum circuit using Qiskit AerSimulator with configurable depolarizing noise. Returns measurement counts, probabilities, and simulation metadata. Select noise preset: ideal, low, or high noise.

Instructions

Run a stored circuit on AerSimulator with optional depolarizing noise. noise_preset: ideal | low_noise | high_noise. Returns counts, probabilities, metadata.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
circuit_idYes
shotsYes
noise_presetYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function 'run_simulation' that executes the tool logic: validates noise_preset, retrieves circuit by ID, builds noise model, runs AerSimulator with given shots, and returns JSON with counts, probabilities, and metadata.
    def run_simulation(circuit_id: str, shots: int, noise_preset: str) -> str:
        if noise_preset not in _VALID_NOISE_PRESETS:
            return json.dumps(mcp_error(
                f"Unknown noise_preset: {noise_preset!r}. Choose from {sorted(_VALID_NOISE_PRESETS)}"
            ))
    
        try:
            circuit = get_circuit(circuit_id)
        except CircuitNotFoundError as e:
            return json.dumps(mcp_error(str(e)))
    
        noise_model = _build_noise_model(noise_preset)
        simulator = AerSimulator(noise_model=noise_model)
        transpiled = transpile(circuit, backend=simulator)
        result = simulator.run(transpiled, shots=shots).result()
        counts_raw = result.get_counts()
        counts = cast_counts(counts_raw)
    
        try:
            verify_shot_count(shots, counts)
        except ShotCountMismatchError as e:
            return json.dumps(mcp_error(str(e)))
    
        return json.dumps({
            "counts": counts,
            "probabilities": to_probabilities(counts),
            "metadata": {"circuit_id": circuit_id, "shots": shots, "noise_preset": noise_preset},
        })
  • Input validation constants: _VALID_NOISE_PRESETS defines accepted noise presets (ideal, low_noise, high_noise) and _NOISE_P maps noise levels to depolarizing error probabilities.
    _VALID_NOISE_PRESETS = {"ideal", "low_noise", "high_noise"}
    _NOISE_P = {"low_noise": 0.001, "high_noise": 0.01}
  • Tool registration in FastMCP server: wraps run_simulation as an MCP tool with description of parameters (circuit_id, shots, noise_preset) and return type.
    mcp.tool(
        description=(
            "Run a stored circuit on AerSimulator with optional depolarizing noise. "
            "noise_preset: ideal | low_noise | high_noise. Returns counts, probabilities, metadata."
        )
    )(run_simulation)
  • Exports run_simulation from the tools package so it can be imported by server.py.
    from .simulate import run_simulation
    
    __all__ = ["create_circuit", "visualize_circuit", "run_simulation"]
  • Helper function _build_noise_model: returns None for 'ideal' or constructs a NoiseModel with depolarizing errors on single- and two-qubit gates for low_noise/high_noise presets.
    def _build_noise_model(preset: str) -> NoiseModel | None:
        if preset == "ideal":
            return None
        p = _NOISE_P[preset]
        nm = NoiseModel()
        nm.add_all_qubit_quantum_error(depolarizing_error(p, 1), ["h", "x", "rx", "ry"])
        nm.add_all_qubit_quantum_error(depolarizing_error(p, 2), ["cx", "cz"])
        return nm
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions returns (counts, probabilities, metadata) but does not state whether the operation is read-only, has side effects, or requires specific permissions. The behavior is partially transparent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences, front-loads the core purpose, and presents noise options succinctly. No wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 3 required parameters, no annotations, and an output schema, the description covers the platform and noise but omits parameter constraints and fails to distinguish output structure beyond mentioning three fields. It is adequate but not rich.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description must compensate. It explains noise_preset with enumerated values, but leaves circuit_id and shots undocumented (no hint on circuit_id source or shots default/range). Only 1 of 3 parameters gains meaning.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool runs a stored circuit on AerSimulator with optional noise, and the verb 'Run' paired with 'stored circuit' distinguishes it from sibling tools 'create_circuit' and 'visualize_circuit'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context (run a stored circuit) and provides specific noise preset options (ideal, low_noise, high_noise), but does not explicitly exclude alternatives or state prerequisites like needing a pre-existing circuit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Narashiman24/qiskit-sim-mcp-demo'

If you have feedback or need assistance with the MCP directory API, please join our Discord server