Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  

Large diffs are not rendered by default.

235 changes: 235 additions & 0 deletions docs/api/qiskit-ibm-runtime/0.46/batch.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
---
title: Batch (v0.46)
description: API reference for qiskit_ibm_runtime.Batch in qiskit-ibm-runtime v0.46
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit_ibm_runtime.Batch
---

# Batch

<Class id="qiskit_ibm_runtime.Batch" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.46/qiskit_ibm_runtime/batch.py#L22-L117" signature="Batch(backend, max_time=None, *, create_new=True)" modifiers="class">
Bases: [`Session`](session "qiskit_ibm_runtime.session.Session")

Class for running jobs in batch execution mode.

The `batch` mode is designed to efficiently perform experiments that comprise multiple independent jobs.

**Using the `batch` mode provides the following benefits:**

* The jobs’ classical computation, such as compilation, is run in parallel. Thus, running multiple jobs in a batch is significantly faster than running them serially.
* There is usually minimal delay between job, which can help avoid drift.
* If you partition your workload into multiple jobs and run them in `batch` mode, you can get results from individual jobs, which makes them more flexible to work with. For example, if a job’s results do not meet your expectations, you can cancel the remaining jobs, or simply re-submit that individual job and avoid re-running the entire workload.

Batch mode can shorten processing time if all jobs are provided at the outset. If you want to submit iterative jobs, use `session` mode instead.

You can open a Qiskit Runtime batch by using this `Batch` class, then submit jobs to one or more primitives.

For example:

```python
import numpy as np
from qiskit.circuit.library import IQP
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit.quantum_info import random_hermitian
from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2 as Sampler, Batch

n_qubits = 127

service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False, min_num_qubits=n_qubits)

rng = np.random.default_rng()
mats = [np.real(random_hermitian(n_qubits, seed=rng)) for _ in range(30)]
circuits = [IQP(mat) for mat in mats]
for circuit in circuits:
circuit.measure_all()

pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
isa_circuits = pm.run(circuits)

max_circuits = 10
all_partitioned_circuits = []
for i in range(0, len(isa_circuits), max_circuits):
all_partitioned_circuits.append(isa_circuits[i : i + max_circuits])
jobs = []
start_idx = 0

with Batch(backend=backend):
sampler = Sampler()
for partitioned_circuits in all_partitioned_circuits:
job = sampler.run(partitioned_circuits)
jobs.append(job)
```

For more details, check the “[Run jobs in a batch](/docs/guides/run-jobs-batch)” page.

Batch constructor.

**Parameters**

* **backend** ([*BackendV2*](/docs/api/qiskit/qiskit.providers.BackendV2)) – Instance of `Backend` class.
* **max\_time** (*int | str | None*) – Maximum amount of time a runtime session can be open before being forcibly closed. Can be specified as seconds (int) or a string like “2h 30m 40s”. This value must be less than the [system imposed maximum](/docs/guides/max-execution-time).
* **create\_new** (*bool | None*) – If True, the POST session API endpoint will be called to create a new session. Prevents creating a new session when `from_id()` is called.

**Raises**

**ValueError** – If an input value is invalid.

## Attributes

### service

<Attribute id="qiskit_ibm_runtime.Batch.service">
Return service associated with this session.

**Returns**

[`qiskit_ibm_runtime.QiskitRuntimeService`](qiskit-runtime-service "qiskit_ibm_runtime.QiskitRuntimeService") associated with this session.
</Attribute>

### session\_id

<Attribute id="qiskit_ibm_runtime.Batch.session_id">
Return the session ID.

**Returns**

Session ID. None if the backend is a simulator.
</Attribute>

## Methods

### backend

<Function id="qiskit_ibm_runtime.Batch.backend" github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.46/qiskit_ibm_runtime/session.py#L207-L215" signature="backend()">
Return backend for this session.

**Returns**

Backend for this session. None if unknown.

**Return type**

str | None
</Function>

### cancel

<Function id="qiskit_ibm_runtime.Batch.cancel" github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.46/qiskit_ibm_runtime/session.py#L193-L197" signature="cancel()">
Cancel all pending jobs in a session.

**Return type**

None
</Function>

### close

<Function id="qiskit_ibm_runtime.Batch.close" github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.46/qiskit_ibm_runtime/session.py#L199-L205" signature="close()">
Close the session so new jobs will no longer be accepted, but existing queued or running jobs will run to completion. The session will be terminated once there are no more pending jobs.

**Return type**

None
</Function>

### details

<Function id="qiskit_ibm_runtime.Batch.details" github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.46/qiskit_ibm_runtime/session.py#L260-L304" signature="details()">
Return session details.

**Returns**

A dictionary with the sessions details.

* `id`: id of the session.
* `backend_name`: backend used for the session.
* `interactive_timeout`: The maximum idle time (in seconds) between jobs that is allowed to occur before the session is deactivated.
* `max_time`: Maximum allowed time (in seconds) for the session, subject to plan limits.
* `active_timeout`: The maximum time (in seconds) a session can stay active.
* `state`: State of the session - open, active, inactive, or closed.
* `accepting_jobs`: Whether or not the session is accepting jobs.
* `last_job_started`: Timestamp of when the last job in the session started.
* `last_job_completed`: Timestamp of when the last job in the session completed.
* `started_at`: Timestamp of when the session was started.
* `closed_at`: Timestamp of when the session was closed.
* `activated_at`: Timestamp of when the session state was changed to active.
* `mode`: Execution mode of the session.
* `usage_time`: The usage time, in seconds, of this Session or Batch. Usage is defined as the time a quantum system is committed to complete a job.

**Return type**

dict\[str, *Any*] | None
</Function>

### from\_id

<Function id="qiskit_ibm_runtime.Batch.from_id" github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.46/qiskit_ibm_runtime/session.py#L324-L386" signature="from_id(session_id, service)" modifiers="classmethod">
Construct a Session object with a given `session_id`. For example:

```python
from qiskit_ibm_runtime import QiskitRuntimeService, Session
service = QiskitRuntimeService()
job = service.job(<job_id>)
existing_session_id = job.session_id

new_session = Session.from_id(existing_session_id, service)
```

**Parameters**

* **session\_id** (*str*) – the id of the session to be created. This must be an already existing session id.

* **service** ([*QiskitRuntimeService*](qiskit-runtime-service "qiskit_ibm_runtime.qiskit_runtime_service.QiskitRuntimeService")) –

instance of the `QiskitRuntimeService` class.

**Raises:**

IBMInputValueError: If given session\_id does not exist. IBMRuntimeError: If the backend of the session is unknown.

**Returns**

A new Session with the given `session_id`

**Return type**

[*Session*](session "qiskit_ibm_runtime.session.Session")
</Function>

### status

<Function id="qiskit_ibm_runtime.Batch.status" github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.46/qiskit_ibm_runtime/session.py#L217-L242" signature="status()">
Return current session status.

**Returns**

Session status as a string.

* `Pending`: Session is created but not active. It will become active when the next job of this session is dequeued.
* `In progress, accepting new jobs`: session is active and accepting new jobs.
* `In progress, not accepting new jobs`: session is active and not accepting new jobs.
* `Closed`: max\_time expired or session was explicitly closed.
* `None`: status details are not available.

**Return type**

str | None
</Function>

### usage

<Function id="qiskit_ibm_runtime.Batch.usage" github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.46/qiskit_ibm_runtime/session.py#L244-L258" signature="usage()">
Return session usage in seconds.

Session usage is the time from when the first job starts until the session goes inactive, is closed, or when its last job completes, whichever happens last.

Batch usage is the amount of time all jobs spend on the QPU.

**Return type**

float | None
</Function>
</Class>

44 changes: 44 additions & 0 deletions docs/api/qiskit-ibm-runtime/0.46/debug-tools-neat-pub-result.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: NeatPubResult (v0.46)
description: API reference for qiskit_ibm_runtime.debug_tools.NeatPubResult in qiskit-ibm-runtime v0.46
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit_ibm_runtime.debug_tools.NeatPubResult
---

# NeatPubResult

<Class id="qiskit_ibm_runtime.debug_tools.NeatPubResult" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.46/qiskit_ibm_runtime/debug_tools/neat_results.py#L29-L116" signature="NeatPubResult(vals)" modifiers="class">
Bases: `object`

A class to store the PUB results of `Neat`.

It allows performing mathematical operations (`+`, `-`, `*`, `/`, `abs`, and `**`) with other objects of type `NeatPubResultLike` and with scalars.

**Parameters**

**vals** (*ArrayLike*) – The values in this `NeatPubResult`.

## Attributes

### vals

<Attribute id="qiskit_ibm_runtime.debug_tools.NeatPubResult.vals">
The values in this result.
</Attribute>

## Methods

### \_\_mul\_\_

<Function id="qiskit_ibm_runtime.debug_tools.NeatPubResult.__mul__" github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.46/qiskit_ibm_runtime/debug_tools/neat_results.py#L91-L92" signature="__mul__(other)">
**Parameters**

**other** (*int | float |* [*NeatPubResult*](#qiskit_ibm_runtime.debug_tools.NeatPubResult "qiskit_ibm_runtime.debug_tools.neat_results.NeatPubResult") *|*[*PubResult*](/docs/api/qiskit/qiskit.primitives.PubResult) *|*[*DataBin*](/docs/api/qiskit/qiskit.primitives.DataBin))

**Return type**

[*NeatPubResult*](#qiskit_ibm_runtime.debug_tools.NeatPubResult "qiskit_ibm_runtime.debug_tools.neat_results.NeatPubResult")
</Function>
</Class>

42 changes: 42 additions & 0 deletions docs/api/qiskit-ibm-runtime/0.46/debug-tools-neat-result.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: NeatResult (v0.46)
description: API reference for qiskit_ibm_runtime.debug_tools.NeatResult in qiskit-ibm-runtime v0.46
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit_ibm_runtime.debug_tools.NeatResult
---

# NeatResult

<Class id="qiskit_ibm_runtime.debug_tools.NeatResult" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.46/qiskit_ibm_runtime/debug_tools/neat_results.py#L119-L139" signature="NeatResult(pub_results)" modifiers="class">
Bases: `object`

A container for multiple [`NeatPubResult`](debug-tools-neat-pub-result "qiskit_ibm_runtime.debug_tools.NeatPubResult") objects.

**Parameters**

**pub\_results** (*Iterable\[*[*NeatPubResult*](debug-tools-neat-pub-result "qiskit_ibm_runtime.debug_tools.NeatPubResult")*]*) – An iterable of [`NeatPubResult`](debug-tools-neat-pub-result "qiskit_ibm_runtime.debug_tools.NeatPubResult") objects.

## Methods

### \_\_getitem\_\_

<Function id="qiskit_ibm_runtime.debug_tools.NeatResult.__getitem__" github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.46/qiskit_ibm_runtime/debug_tools/neat_results.py#L129-L130" signature="__getitem__(index)">
**Parameters**

**index** (*int*)

**Return type**

[*NeatPubResult*](debug-tools-neat-pub-result "qiskit_ibm_runtime.debug_tools.neat_results.NeatPubResult")
</Function>

### \_\_len\_\_

<Function id="qiskit_ibm_runtime.debug_tools.NeatResult.__len__" github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.46/qiskit_ibm_runtime/debug_tools/neat_results.py#L132-L133" signature="__len__()">
**Return type**

int
</Function>
</Class>

Loading
Loading