> ## Documentation Index
> Fetch the complete documentation index at: https://docs.haiqu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Backpropagate Observables Mcp

> Backpropagate observables through a circuit to shorten what must be run.

Use this tool to move part of the computation from the circuit into the
observable: Haiqu rewrites each observable through the tail of the circuit and
stores a correspondingly shortened circuit. Running the shorter circuit with
the rewritten observable estimates the same expectation value with less
hardware noise.

When to Use:
    - Call this when the user wants expectation values from a circuit that is
      too deep to run faithfully on hardware.
    - Call this before ``run_circuits_on_qpu_or_simulator`` for
      expectation-value workloads, and pass the returned circuit and
      observable together.

Constraints:
    - Backpropagation is synchronous and runs no quantum job.
    - Each input observable yields one output circuit, returned under the same
      key you gave the observable: run ``optimized_circuit_ids[name]`` with
      ``backpropagated_observables[name]``.
    - Truncation budgets trade accuracy for depth. Without
      ``max_error_total`` or ``max_error_per_slice`` the rewritten observable
      can grow large.

Notes:
    - Pauli coefficients are given and returned as ``(pauli, real, imaginary)``
      triples, one per term -- not as the parallel ``(pauli_strings,
      coefficients)`` lists that ``run_variational_workload`` and
      ``run_circuits_on_qpu_or_simulator`` take.
    - Compare the returned circuits against the input with
      ``get_circuit_by_id`` to show how much depth was removed.

Args:
    user: Authenticated user resolved from the API key.
    data: Circuit identifier, observables, and optional truncation budgets.
    db: Active database session.

Returns:
    The generated circuit IDs with their rewritten observables.

Raises:
    HTTPException: Raised with ``404`` when the circuit is not available to
        the caller, ``422`` when an observable cannot be parsed, or ``501``
        when the backpropagation dependency is unavailable.



## OpenAPI

````yaml https://api.haiqu.ai/openapi.json post /ai/backpropagate_observables
openapi: 3.1.0
info:
  title: Haiqu API
  summary: Haiqu RESTful API service.
  description: Cloud service providing the access to Haiqu cloud runtime
  contact:
    name: Haiqu Inc.
    url: https://haiqu.ai/
    email: info@haiqu.ai
  version: 1.6.0
servers: []
security: []
paths:
  /ai/backpropagate_observables:
    post:
      summary: Backpropagate Observables Mcp
      description: >-
        Backpropagate observables through a circuit to shorten what must be run.


        Use this tool to move part of the computation from the circuit into the

        observable: Haiqu rewrites each observable through the tail of the
        circuit and

        stores a correspondingly shortened circuit. Running the shorter circuit
        with

        the rewritten observable estimates the same expectation value with less

        hardware noise.


        When to Use:
            - Call this when the user wants expectation values from a circuit that is
              too deep to run faithfully on hardware.
            - Call this before ``run_circuits_on_qpu_or_simulator`` for
              expectation-value workloads, and pass the returned circuit and
              observable together.

        Constraints:
            - Backpropagation is synchronous and runs no quantum job.
            - Each input observable yields one output circuit, returned under the same
              key you gave the observable: run ``optimized_circuit_ids[name]`` with
              ``backpropagated_observables[name]``.
            - Truncation budgets trade accuracy for depth. Without
              ``max_error_total`` or ``max_error_per_slice`` the rewritten observable
              can grow large.

        Notes:
            - Pauli coefficients are given and returned as ``(pauli, real, imaginary)``
              triples, one per term -- not as the parallel ``(pauli_strings,
              coefficients)`` lists that ``run_variational_workload`` and
              ``run_circuits_on_qpu_or_simulator`` take.
            - Compare the returned circuits against the input with
              ``get_circuit_by_id`` to show how much depth was removed.

        Args:
            user: Authenticated user resolved from the API key.
            data: Circuit identifier, observables, and optional truncation budgets.
            db: Active database session.

        Returns:
            The generated circuit IDs with their rewritten observables.

        Raises:
            HTTPException: Raised with ``404`` when the circuit is not available to
                the caller, ``422`` when an observable cannot be parsed, or ``501``
                when the backpropagation dependency is unavailable.
      operationId: backpropagate_observables
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContextBackpropagationSubmitModel'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContextBackpropagationResultModel'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyQuery: []
        - APIKeyHeader: []
components:
  schemas:
    ContextBackpropagationSubmitModel:
      properties:
        circuit_id:
          type: string
          title: Circuit Id
        observables:
          additionalProperties:
            items:
              prefixItems:
                - type: string
                - type: number
                - type: number
              type: array
              maxItems: 3
              minItems: 3
            type: array
          type: object
          minProperties: 1
          title: Observables
          description: >-
            Observables to backpropagate, keyed by a name you choose. Each
            observable is a list of Pauli terms given as `[pauli_string,
            real_coefficient, imaginary_coefficient]`, for example `{"energy":
            [["ZZ", 1.0, 0.0], ["XX", 0.5, 0.0]]}`. The results come back under
            the same keys.
        max_qwc_groups:
          anyOf:
            - type: integer
            - type: 'null'
          title: Max Qwc Groups
          description: Optional cap on the number of qubit-wise-commuting groups retained.
        max_error_total:
          anyOf:
            - type: number
            - type: 'null'
          title: Max Error Total
          description: Optional total truncation error budget across the backpropagation.
        max_error_per_slice:
          anyOf:
            - type: number
            - type: 'null'
          title: Max Error Per Slice
          description: Optional truncation error budget per circuit slice.
      type: object
      required:
        - circuit_id
        - observables
      title: ContextBackpropagationSubmitModel
      description: |-
        Define payload for backpropagating observables through a circuit.

        Attributes:
            circuit_id: Circuit to backpropagate through.
            observables: Observables to rewrite, keyed by caller-chosen names. Each is
                a list of ``(pauli, real, imaginary)`` terms.
            max_qwc_groups: Optional cap on qubit-wise-commuting groups.
            max_error_total: Optional total truncation error budget.
            max_error_per_slice: Optional per-slice truncation error budget.
      examples:
        - circuit_id: circ-123
          max_error_total: 0.01
          observables:
            energy:
              - - ZZ
                - 1
                - 0
    ContextBackpropagationResultModel:
      properties:
        optimized_circuit_ids:
          additionalProperties:
            type: string
          type: object
          title: Optimized Circuit Ids
        backpropagated_observables:
          additionalProperties:
            items:
              prefixItems:
                - type: string
                - type: number
                - type: number
              type: array
              maxItems: 3
              minItems: 3
            type: array
          type: object
          title: Backpropagated Observables
        context:
          type: string
          title: Context
      type: object
      required:
        - optimized_circuit_ids
        - backpropagated_observables
        - context
      title: ContextBackpropagationResultModel
      description: |-
        Represent the outcome of an observable backpropagation.

        Attributes:
            optimized_circuit_ids: Circuit produced for each input observable, keyed by
                the input's name.
            backpropagated_observables: Rewritten observables as
                ``(pauli, real, imaginary)`` term lists, keyed by the input's name.
            context: Summary of what was produced and the next step.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyQuery:
      type: apiKey
      in: query
      name: HAIQU_API_KEY
    APIKeyHeader:
      type: apiKey
      in: header
      name: authorization

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.