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

# Compress Circuit With State Compression

> Submit state-compression jobs for existing or inline circuits.

Use this tool when the caller wants to run Haiqu state compression on
either an existing stored circuit or a new inline QASM payload. At least
one of ``circuit_ids`` or ``circuit_qasm`` must be supplied, and the
response schema is a lightweight ``{"context": ...}`` wrapper rather than a
structured job object.

When to Use:
    - Call this when the workflow needs a compressed or optimized circuit
      derived from an existing circuit or from inline QASM.
    - Call this before later execution or circuit analysis when the user
      wants Haiqu state compression applied first.

Constraints:
    - Provide at least one of ``circuit_ids`` or ``circuit_qasm``.
    - The response is a lightweight context wrapper; use
      ``get_job_results_and_status`` to retrieve terminal outputs such as
      the generated circuit ID.
    - This docstring does not promise normalized ``404`` handling for every
      invalid circuit reference because the lower-layer compression path
      owns part of that behavior.

Notes:
    - If inline QASM is provided, the endpoint may create a circuit first
      and then submit compression.
    - The created or reused input circuit is stored as ``input_circuit_id``
      in the job record.
    - There is no practical size limit on ``circuit_qasm``. For circuits
      already stored, prefer ``circuit_ids`` so large QASM payloads are
      sent at most once; never downscale an instance because its QASM
      looks large.

The batch of compression jobs could be submitted via `circuit_ids`. If both
`circuit_ids` and `circuit_id` are provided, `circuit_ids` will be used and
`circuit_id` will be ignored, it is deprecated.

Args:
    user: Authenticated user resolved from the API key.
    data: Compression payload. One of ``circuit_ids`` or ``circuit_qasm``
        must be provided.
    db: Active database session.

Returns:
    A lightweight context wrapper summarizing the submission and next
    polling step.

Raises:
    HTTPException: Raised with ``400`` when neither circuit input mode is
        provided, ``402`` when the caller cannot submit billable jobs, or
        ``404`` when the experiment is not available to the caller.



## OpenAPI

````yaml https://api.haiqu.ai/openapi.json post /ai/compress_circuit_with_state_compression
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.4.0
servers: []
security: []
paths:
  /ai/compress_circuit_with_state_compression:
    post:
      summary: Compress Circuit With State Compression
      description: >-
        Submit state-compression jobs for existing or inline circuits.


        Use this tool when the caller wants to run Haiqu state compression on

        either an existing stored circuit or a new inline QASM payload. At least

        one of ``circuit_ids`` or ``circuit_qasm`` must be supplied, and the

        response schema is a lightweight ``{"context": ...}`` wrapper rather
        than a

        structured job object.


        When to Use:
            - Call this when the workflow needs a compressed or optimized circuit
              derived from an existing circuit or from inline QASM.
            - Call this before later execution or circuit analysis when the user
              wants Haiqu state compression applied first.

        Constraints:
            - Provide at least one of ``circuit_ids`` or ``circuit_qasm``.
            - The response is a lightweight context wrapper; use
              ``get_job_results_and_status`` to retrieve terminal outputs such as
              the generated circuit ID.
            - This docstring does not promise normalized ``404`` handling for every
              invalid circuit reference because the lower-layer compression path
              owns part of that behavior.

        Notes:
            - If inline QASM is provided, the endpoint may create a circuit first
              and then submit compression.
            - The created or reused input circuit is stored as ``input_circuit_id``
              in the job record.
            - There is no practical size limit on ``circuit_qasm``. For circuits
              already stored, prefer ``circuit_ids`` so large QASM payloads are
              sent at most once; never downscale an instance because its QASM
              looks large.

        The batch of compression jobs could be submitted via `circuit_ids`. If
        both

        `circuit_ids` and `circuit_id` are provided, `circuit_ids` will be used
        and

        `circuit_id` will be ignored, it is deprecated.


        Args:
            user: Authenticated user resolved from the API key.
            data: Compression payload. One of ``circuit_ids`` or ``circuit_qasm``
                must be provided.
            db: Active database session.

        Returns:
            A lightweight context wrapper summarizing the submission and next
            polling step.

        Raises:
            HTTPException: Raised with ``400`` when neither circuit input mode is
                provided, ``402`` when the caller cannot submit billable jobs, or
                ``404`` when the experiment is not available to the caller.
      operationId: compress_circuit_with_state_compression
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContextStateCompressionSubmitModel'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContextStateCompressionJobModel'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyQuery: []
        - APIKeyHeader: []
components:
  schemas:
    ContextStateCompressionSubmitModel:
      properties:
        experiment_id:
          type: string
          title: Experiment Id
        circuit_ids:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Circuit Ids
          description: List of existing circuit IDs to compress.
        compression_type:
          type: string
          title: Compression Type
          default: StateCompression
        parameters:
          additionalProperties: true
          type: object
          title: Parameters
          description: >-
            State compression options: `compression_level`
            (`low`|`balanced`|`high`|`max`), `noise_profile` (e.g. `default`,
            `ibm_heron_r2`, `iqm_garnet`), `fine_tuning`
            (`disabled`|`low`|`heavy`, defaults to `disabled` if omitted), and
            optional `approximation_level` (int or null).
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
          description: >-
            Name for the circuit to compress. Required if `circuit_qasm` is
            provided without `circuit_id`.
        circuit_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Circuit Id
          description: ID of the existing circuit to compress. Deprecated.
        circuit_qasm:
          anyOf:
            - type: string
            - type: 'null'
          title: Circuit Qasm
          description: >-
            Quantum circuit in QASM 2.0 or 3.0 format. Use either this field or
            `circuit_id` field to specify the existing circuit ID to compress.
      type: object
      required:
        - experiment_id
        - parameters
      title: ContextStateCompressionSubmitModel
      description: >-
        Define payload for MCP state-compression submissions.


        The request may reference either an existing ``circuit_id`` or inline

        ``circuit_qasm``; endpoint-level validation enforces that at least one
        is

        present.


        Attributes:
            experiment_id: Parent experiment identifier for the compression job.
            name: Optional name to use when a new circuit must be created from
                inline QASM.
            circuit_id: Existing circuit ID to compress. Deprecated.
            circuit_ids: Existing circuit IDs to compress.
            circuit_qasm: Inline QASM source to persist and compress.
            compression_type: Compression backend or mode identifier. The default
                value should normally be left unchanged.
            parameters: Compression configuration forwarded to the backend.
      examples:
        - circuit_ids:
            - circ-abc123
            - circ-def456
          experiment_id: exp-123
          parameters:
            compression_level: balanced
            fine_tuning: low
            noise_profile: default
        - circuit_qasm: |-
            OPENQASM 3;
            qubit[2] q;
            h q[0];
            cx q[0], q[1];
          experiment_id: exp-123
          name: Bell pair circuit
          parameters:
            approximation_level: 2
            compression_level: high
            fine_tuning: heavy
            noise_profile: ibm_heron_r2
    ContextStateCompressionJobModel:
      properties:
        context:
          type: string
          title: Context
      type: object
      required:
        - context
      title: ContextStateCompressionJobModel
      description: |-
        Represent context payload returned after compression job creation.

        Attributes:
            context: Submission summary text including the created job ID and next
                polling step. This response model does not expose structured
                ``job_id`` or output ``circuit_id`` fields outside the text.
    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

````