Helpers¶
Helper methods for mapping Qiskit classes to IonQ REST API compatible values.
- qiskit_ionq.helpers.compress_to_metadata_string(metadata: dict | list) str [source]¶
Convert a metadata object to a compact string format (dumped, gzipped, base64 encoded) for storing in IonQ API metadata
- Parameters:
metadata (dict or list) – a dict or list of dicts with metadata relevant to building the results object on a returned job.
- Returns:
encoded string
- Return type:
str
- qiskit_ionq.helpers.decompress_metadata_string(input_string: str) dict | list [source]¶
Convert compact string format (dumped, gzipped, base64 encoded) from IonQ API metadata back into a dict or list of dicts relevant to building the results object on a returned job.
- Parameters:
input_string (str) – compressed string format of metadata dict
- Returns:
decompressed metadata dict or list of dicts
- Return type:
dict or list
- qiskit_ionq.helpers.get_n_qubits(backend: str, _fallback=100) int [source]¶
Get the number of qubits for a given backend.
- Parameters:
backend (str) – The name of the backend.
- Returns:
The number of qubits for the backend.
- Return type:
int
- qiskit_ionq.helpers.get_user_agent()[source]¶
Generates the user agent string which is helpful in identifying different tools in the internet. Valid user-agent ionq_client header that indicates the request is from qiskit_ionq along with the system, os, python,libraries details.
- Returns:
A string of generated user agent.
- Return type:
str
- qiskit_ionq.helpers.qiskit_circ_to_ionq_circ(input_circuit: QuantumCircuit, gateset: Literal['qis', 'native'] = 'qis')[source]¶
Build a circuit in IonQ’s instruction format from qiskit instructions.
Attention
This function ignores the following compiler directives: *
barrier
- Parameters:
input_circuit (
qiskit.circuit.QuantumCircuit
) – A Qiskit quantum circuit.gateset (string) – Set of gates to target. It can be QIS (required transpilation pass in IonQ backend, which is sent standard gates) or native (only IonQ native gates are allowed, in the future we may provide transpilation to these gates in Qiskit).
- Raises:
IonQGateError – If an unsupported instruction is supplied.
IonQMidCircuitMeasurementError – If a mid-circuit measurement is detected.
- Returns:
A list of instructions in a converted dict format. int: The number of measurements. dict: The measurement map from qubit number to classical bit number.
- Return type:
list[dict]
- qiskit_ionq.helpers.qiskit_to_ionq(circuit, backend, passed_args=None, extra_query_params=None, extra_metadata=None) str [source]¶
Convert a Qiskit circuit to a IonQ compatible dict.
- Parameters:
circuit (
qiskit.circuit.QuantumCircuit
) – A Qiskit quantum circuit.backend (
qiskit_ionq.IonQBackend
) – The IonQ backend.passed_args (dict) – Dictionary containing additional passed arguments, eg. shots.
extra_query_params (dict) – Specify any parameters to include in the request
extra_metadata (dict) – Specify any additional metadata to include.
- Returns:
A string / JSON-serialized dictionary with IonQ API compatible values.
- Return type:
str
- qiskit_ionq.helpers.resolve_credentials(token: str | None = None, url: str | None = None)[source]¶
Resolve credentials for use in IonQ API calls.
If the provided
token
andurl
are bothNone
, then these values are loaded from theIONQ_API_TOKEN
andIONQ_API_URL
environment variables, respectively.If no url is discovered, then
https://api.ionq.co/v0.3
is used.- Parameters:
token (str) – IonQ API access token.
url (str, optional) – IonQ API url. Defaults to
None
.
- Returns:
A dict with “token” and “url” keys, for use by a client.
- Return type:
dict[str]