> ## 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.

# Build Lr Qaoa Circuit Mcp

> Build and store a linear-ramp QAOA circuit for a QUBO problem.

Use this tool to turn a combinatorial optimization problem into a runnable
circuit without writing QASM. Generation is synchronous: the circuit is
stored and returned immediately, with core analytics already computed.

When to Use:
    - Call this when the user has a QUBO or MaxCut-style problem in LP format
      and wants to run QAOA on it.
    - Call this instead of ``submit_circuit_for_analytics`` when Haiqu should
      construct the ansatz rather than the caller.

Constraints:
    - ``lp_problem`` must parse as an LP-format QUBO with binary variables.
    - ``alphas`` and ``betas`` must each have length ``p`` when supplied. Omit
      both to use the linear ramp defined by ``delta``.
    - Nothing is executed here. Run the returned ``id`` with
      ``run_circuits_on_qpu_or_simulator``.

Notes:
    - The linear-ramp schedule needs no classical outer loop, which is what
      makes LR-QAOA cheap compared with parameter-optimized QAOA.
    - Keep the same ``lp_problem`` string for
      ``postprocess_measurement_counts`` so the objective matches.

Args:
    user: Authenticated user resolved from the API key.
    data: Problem definition, layer count, and optional schedule.
    db: Active database session.

Returns:
    The stored circuit enriched with MCP context text.

Raises:
    HTTPException: Raised with ``404`` when the experiment is not available to
        the caller, or ``500`` when circuit generation fails.



## OpenAPI

````yaml https://api.haiqu.ai/openapi.json post /ai/build_lr_qaoa_circuit
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.5.0
servers: []
security: []
paths:
  /ai/build_lr_qaoa_circuit:
    post:
      summary: Build Lr Qaoa Circuit Mcp
      description: >-
        Build and store a linear-ramp QAOA circuit for a QUBO problem.


        Use this tool to turn a combinatorial optimization problem into a
        runnable

        circuit without writing QASM. Generation is synchronous: the circuit is

        stored and returned immediately, with core analytics already computed.


        When to Use:
            - Call this when the user has a QUBO or MaxCut-style problem in LP format
              and wants to run QAOA on it.
            - Call this instead of ``submit_circuit_for_analytics`` when Haiqu should
              construct the ansatz rather than the caller.

        Constraints:
            - ``lp_problem`` must parse as an LP-format QUBO with binary variables.
            - ``alphas`` and ``betas`` must each have length ``p`` when supplied. Omit
              both to use the linear ramp defined by ``delta``.
            - Nothing is executed here. Run the returned ``id`` with
              ``run_circuits_on_qpu_or_simulator``.

        Notes:
            - The linear-ramp schedule needs no classical outer loop, which is what
              makes LR-QAOA cheap compared with parameter-optimized QAOA.
            - Keep the same ``lp_problem`` string for
              ``postprocess_measurement_counts`` so the objective matches.

        Args:
            user: Authenticated user resolved from the API key.
            data: Problem definition, layer count, and optional schedule.
            db: Active database session.

        Returns:
            The stored circuit enriched with MCP context text.

        Raises:
            HTTPException: Raised with ``404`` when the experiment is not available to
                the caller, or ``500`` when circuit generation fails.
      operationId: build_lr_qaoa_circuit
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContextLRQAOASubmitModel'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContextCircuitModel'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyQuery: []
        - APIKeyHeader: []
components:
  schemas:
    ContextLRQAOASubmitModel:
      properties:
        experiment_id:
          type: string
          title: Experiment Id
        lp_problem:
          type: string
          title: Lp Problem
          description: >-
            QUBO problem serialized in LP file format, the same format accepted
            by `postprocess_measurement_counts`.
        p:
          type: integer
          minimum: 1
          title: P
          description: Number of QAOA layers (circuit depth multiplier).
        name:
          type: string
          title: Name
        alphas:
          anyOf:
            - items:
                type: number
              type: array
            - type: 'null'
          title: Alphas
          description: >-
            Optional explicit per-layer cost-Hamiltonian angles. Length must
            equal `p`.
        betas:
          anyOf:
            - items:
                type: number
              type: array
            - type: 'null'
          title: Betas
          description: Optional explicit per-layer mixer angles. Length must equal `p`.
        delta:
          type: number
          title: Delta
          description: >-
            Linear-ramp slope used to derive the schedule when `alphas`/`betas`
            are omitted.
          default: 0.5
      type: object
      required:
        - experiment_id
        - lp_problem
        - p
        - name
      title: ContextLRQAOASubmitModel
      description: |-
        Define payload for building an LR-QAOA circuit from a QUBO problem.

        Attributes:
            experiment_id: Parent experiment identifier for the generated circuit.
            lp_problem: QUBO problem in LP file format.
            p: Number of QAOA layers.
            name: Circuit name.
            alphas: Optional per-layer cost-Hamiltonian schedule.
            betas: Optional per-layer mixer schedule.
            delta: Linear-ramp slope used when no explicit schedule is given.
      examples:
        - delta: 0.5
          experiment_id: exp-123
          lp_problem: |-
            Maximize
             obj: x0 + x1
            Binary
             x0
             x1
            End
          name: maxcut-ring-8 lr-qaoa p=3
          p: 3
    ContextCircuitModel:
      properties:
        id:
          type: string
          title: Id
        hash:
          type: string
          title: Hash
        name:
          type: string
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
          default: ''
        creation_date:
          type: string
          format: date-time
          title: Creation Date
        user_id:
          type: integer
          title: User Id
        experiment_id:
          type: string
          title: Experiment Id
        tags:
          anyOf:
            - type: string
            - type: 'null'
          title: Tags
          default: ''
        status:
          $ref: '#/components/schemas/CircuitStatus'
        generated:
          type: boolean
          title: Generated
        parameters:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Parameters
        analytics:
          anyOf:
            - $ref: '#/components/schemas/CircuitAnalyticsModel'
            - type: 'null'
        transpilation_target:
          anyOf:
            - type: string
            - type: 'null'
          title: Transpilation Target
        transpilation_options:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Transpilation Options
        transpiled_circuit_ids:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Transpiled Circuit Ids
        compressed_circuit_ids:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Compressed Circuit Ids
        job_ids:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Job Ids
        context:
          type: string
          title: Context
      type: object
      required:
        - id
        - hash
        - name
        - creation_date
        - user_id
        - experiment_id
        - status
        - generated
        - context
      title: ContextCircuitModel
      description: |-
        Extend a stored circuit model with MCP context text.

        Attributes:
            context: ai summary describing the circuit role in the workflow.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    CircuitStatus:
      type: string
      enum:
        - Submitted
        - Running analytics computation
        - Core metrics computation is done
        - Advanced metrics computation is done
        - Parameterized QML metrics computation is done
        - Evolution computation is done
        - Done
        - Error
      title: CircuitStatus
      description: Class for circuit analytics calculation job status.
    CircuitAnalyticsModel:
      properties:
        qubits:
          type: integer
          minimum: 1
          title: Qubits
          description: Number of qubits (must be >= 1)
        num_qubits_active:
          anyOf:
            - type: integer
            - type: 'null'
          title: Num Qubits Active
        num_parameters:
          anyOf:
            - type: integer
            - type: 'null'
          title: Num Parameters
        depth:
          type: integer
          title: Depth
        depth_2q:
          type: integer
          title: Depth 2Q
        gates_1q:
          type: integer
          title: Gates 1Q
        gates_2q:
          type: integer
          title: Gates 2Q
        other_gates:
          anyOf:
            - type: integer
            - type: 'null'
          title: Other Gates
        gates_total:
          type: integer
          title: Gates Total
        other_ops:
          type: integer
          title: Other Ops
        instructions_total:
          anyOf:
            - type: integer
            - type: 'null'
          title: Instructions Total
        operations_counts:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Operations Counts
        gate_size_distribution:
          anyOf:
            - additionalProperties:
                type: number
              type: object
            - type: 'null'
          title: Gate Size Distribution
        gate_diversity:
          anyOf:
            - additionalProperties:
                type: number
              type: object
            - type: 'null'
          title: Gate Diversity
        gate_diversity_basis_gates:
          anyOf:
            - additionalProperties:
                type: number
              type: object
            - type: 'null'
          title: Gate Diversity Basis Gates
        gate_count_distribution:
          anyOf:
            - additionalProperties:
                type: integer
              type: object
            - type: 'null'
          title: Gate Count Distribution
        program_communication:
          anyOf:
            - type: number
            - type: string
            - type: 'null'
          title: Program Communication
          default: N/A
        critical_depth:
          anyOf:
            - type: number
            - type: string
            - type: 'null'
          title: Critical Depth
          default: N/A
        entanglement_ratio:
          anyOf:
            - type: number
            - type: string
            - type: 'null'
          title: Entanglement Ratio
          default: N/A
        parallelism:
          anyOf:
            - type: number
            - type: string
            - type: 'null'
          title: Parallelism
          default: N/A
        liveness_per_qubit:
          anyOf:
            - items: {}
              type: array
            - type: string
            - type: 'null'
          title: Liveness Per Qubit
          default: N/A
        liveness:
          anyOf:
            - type: number
            - type: string
            - type: 'null'
          title: Liveness
          default: N/A
        correlation_matrix:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Correlation Matrix
        kl_divergence:
          anyOf:
            - type: number
            - type: string
            - type: 'null'
          title: Kl Divergence
          default: N/A
        entanglement_capability:
          anyOf:
            - type: number
            - type: string
            - type: 'null'
          title: Entanglement Capability
          default: N/A
        expressibility:
          anyOf:
            - type: number
            - type: string
            - type: 'null'
          title: Expressibility
          default: N/A
        quantum_fisher_information_matrix:
          anyOf:
            - items: {}
              type: array
            - type: string
            - type: 'null'
          title: Quantum Fisher Information Matrix
          default: N/A
        circuit_normalized:
          anyOf:
            - type: string
            - type: 'null'
          title: Circuit Normalized
      type: object
      required:
        - qubits
        - depth
        - depth_2q
        - gates_1q
        - gates_2q
        - gates_total
        - other_ops
      title: CircuitAnalyticsModel
      description: Data model for circuit metrics.
    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

````