cosmiq.library.iqp#

cosmiq.library.iqp: IQP circuits and the ZZ feature map, built with Qiskit’s own iqp and zz_feature_map and restricted to the register’s CZ graph, so they transpile with no SWAPs. Needs the extra: pip install "cosmiq[qiskit]".

  • zz_map, iqp_map, random_map: a FeatureMap, the circuit with its register and device;

  • probabilities: the output distribution, from the digital path’s simulator;

  • kernel: the fidelity kernel \(|\langle \varphi(x) | \varphi(x') \rangle|^2\), exact, or sampled through cosmiq.qiskit.SamplerV2.

Qiskit’s random_iqp draws couplings between every pair. On a register, random_map draws the same integers (0-7) on the CZ pairs only and builds with Qiskit’s iqp.

FeatureMap

A circuit on register's atoms (qubit q is atom q), for device's digital profile.

cz_pairs

The register's CZ graph on device's digital profile: each pair (i, j), i < j, within its cz_range_um.

iqp_map

Qiskit's iqp(interactions): an n x n symmetric integer matrix, the T powers on its diagonal and the CS powers above it.

kernel

\(K[i, j] = |\langle \varphi(x1_i) | \varphi(x2_j) \rangle|^2\), [len(x1), len(x2)] float64 (x2 = x1 by default).

probabilities

The output distribution of feature_map with its parameters bound to values (none for a map without), \([2^n]\) float64 in Qiskit's order (qubit 0 the lowest bit), from the digital path's own simulator, noise off.

random_map

A random IQP circuit on the register's CZ graph: integers 0-7 (numpy's default_rng(seed)) on the diagonal and the CZ pairs, built with Qiskit's iqp.

zz_map

Qiskit's zz_feature_map with one feature per atom, reps repetitions, and its ZZ terms on the register's CZ pairs only.

Classes

class cosmiq.library.iqp.FeatureMap(circuit: QuantumCircuit, register: Register, device: str)#

Bases: object

A circuit on register‘s atoms (qubit q is atom q), for device‘s digital profile. Its parameters, if any, are the data: num_features of them, in circuit.parameters‘ order.

circuit: QuantumCircuit#
register: Register#
device: str#
property num_features: int#
property transpiled: QuantumCircuit#

The circuit on cosmiq.qiskit.target(device, register): the trivial layout, and no routing at all (routing_method="none" raises if a SWAP were needed).

Functions

cosmiq.library.iqp.cz_pairs(register: Register, device: str = 'cosmiq-ref-1') → list[tuple[int, int]]#

The register’s CZ graph on device‘s digital profile: each pair (i, j), i < j, within its cz_range_um.

cosmiq.library.iqp.iqp_map(register: Register, interactions: object, *, device: str = 'cosmiq-ref-1') → FeatureMap#

Qiskit’s iqp(interactions): an n x n symmetric integer matrix, the T powers on its diagonal and the CS powers above it. Off the diagonal, only the register’s CZ pairs may be non-zero (LIB_CZ_GRAPH).

cosmiq.library.iqp.kernel(x1: object, x2: object = None, *, feature_map: FeatureMap, shots: int | None = None, seed: int | None = None) → Tensor#

\(K[i, j] = |\langle \varphi(x1_i) | \varphi(x2_j) \rangle|^2\), [len(x1), len(x2)] float64 (x2 = x1 by default).

Exact from the simulator’s states, or with shots= the fraction of all-zero outcomes of \(\varphi(x2_j)^\dagger \varphi(x1_i)\) through cosmiq.qiskit.SamplerV2 (noise off, seeded by seed).

cosmiq.library.iqp.probabilities(feature_map: FeatureMap, values: object = None) → Tensor#

The output distribution of feature_map with its parameters bound to values (none for a map without), \([2^n]\) float64 in Qiskit’s order (qubit 0 the lowest bit), from the digital path’s own simulator, noise off.

cosmiq.library.iqp.random_map(register: Register, *, seed: int, device: str = 'cosmiq-ref-1') → FeatureMap#

A random IQP circuit on the register’s CZ graph: integers 0-7 (numpy’s default_rng(seed)) on the diagonal and the CZ pairs, built with Qiskit’s iqp.

cosmiq.library.iqp.zz_map(register: Register, reps: int = 2, *, device: str = 'cosmiq-ref-1') → FeatureMap#

Qiskit’s zz_feature_map with one feature per atom, reps repetitions, and its ZZ terms on the register’s CZ pairs only.