The algorithm library (cosmiq.library)#

Ready-made building blocks for three tasks on neutral atoms:

  • maximum independent sets, with the atoms placed on a graph’s vertices;

  • time-series prediction, with the atoms as a reservoir that a linear model reads out;

  • kernel methods, with IQP circuits on the digital path as a quantum kernel for machine learning.

Each follows a published method (below), so you can try these ideas on cosmiq’s programs without writing them from scratch. No quantum advantage is claimed for any of them.

Maximum independent sets (mis)#

An independent set of a graph is a set of vertices with no edge between any two of them, and finding the largest one is hard in general. Atoms suit the problem: two atoms close together can’t both be excited (the blockade), so the excited atoms tend to form an independent set of the graph that joins close atoms.

import numpy as np

import cosmiq as cq
from cosmiq.library import graphs, mis

mask = np.array([[1, 1, 0, 1], [0, 1, 1, 1], [1, 0, 1, 1]], dtype=bool)  # the occupied sites
register, graph = graphs.kings(3, 4, filling=mask)  # atoms on a 3 x 4 grid, and their graph
program = mis.program(register)  # the standard sweep, checked against cosmiq-ref-1
result = cq.Emulator().run(program(), shots=1000, seed=1)
sets = mis.postprocess(result, graph)  # every shot turned into a valid, maximal set
print(mis.report(sets, graph))
  • graphs.kings, graphs.square and graphs.triangular place atoms on a lattice, with an optional mask of occupied sites, and return the register and its graph: each site is joined to its eight, four or six nearest neighbours. graphs.from_positions(positions, device=..., omega=...) takes atoms where you put them. There’s no embedder for arbitrary graphs.

  • The spacing is chosen so that the blockade gives exactly the intended graph: joined atoms interact strongly, the others weakly. A layout with a pair in between has no clean graph, and is refused (LIB_MARGIN), naming that pair.

  • mis.program(register) is the standard adiabatic sweep: the drive ramps up, the detuning goes slowly from negative to positive, and the drive ramps down, over 4 µs by default. Its strength and detunings are the program’s parameters, so it trains like any cosmiq program. Build the graph and the program with the same drive strength, or the program is refused.

  • mis.postprocess(shots, graph) makes every shot a valid answer. It repairs a shot by dropping, while two chosen vertices share an edge, the one with the most chosen neighbours, then fills it by adding every vertex that has no chosen neighbour. A lost atom counts as not chosen.

  • mis.report(shots, graph) compares the shots with the exact answer: the exact maximum size, the best size found, and the fractions of shots that are independent, maximal and maximum. mis.exact_size(graph) and mis.count_sets(graph) give the exact answers on their own, up to 24 vertices.

Graph(n, edges) is a plain, immutable graph. It also checks shots on their own:

from cosmiq.library import Graph

g = Graph(4, [(0, 1), (1, 2), (2, 3)])  # a path of four vertices
bits = np.array([[1, 0, 1, 0], [1, 1, 0, 0]])
g.independent(bits), g.maximal(bits)  # [True, False] and [True, False]
g.neighbours(1), g.degrees()  # (0, 2) and [1, 2, 2, 1]

The quality of the sweep is tested on small kings graphs, without noise; other graphs and settings run, but aren’t graded (the evidence).

The reservoir (reservoir)#

In reservoir computing, a fixed system turns the recent inputs into many features, and a simple linear model trained on those features makes the prediction. Here the atoms are the reservoir: each input in a window sets the detuning for a short segment of the drive, and the features are each atom’s excitation and each pair’s correlation at the end of the window.

import numpy as np

import cosmiq as cq
from cosmiq.library import reservoir

u, y = reservoir.narma2(440, seed=0)  # a standard benchmark series: inputs u, targets y
windows = reservoir.windows(u, 4)[:-1]  # window k holds u[k], ..., u[k + 3] ...
targets = y[4:]  # ... and predicts y[k + 4]

x = np.cumsum([0.0, 7.5, 8.0, 8.5, 9.0, 7.0, 8.5, 9.5])  # µm: uneven gaps, so no mirror symmetry
register = cq.Register.from_coordinates([(float(xi - x[-1] / 2), 0.0) for xi in x])
res = reservoir.Reservoir(register, "cosmiq-ref-1", window=4, segment=0.5, input_range=(0.0, 0.5))
features = res.features(windows)  # [436, 36]: 8 densities and 28 pair correlations
model = reservoir.Ridge(1e-6).fit(features[:300], targets[:300])
print(reservoir.nmse(model.predict(features[300:]), targets[300:]))

# The classical baseline: the same linear model on polynomial features of the raw window.
poly = reservoir.poly_features(windows, 2)
baseline = reservoir.Ridge(1e-6).fit(poly[:300], targets[:300])
print(reservoir.nmse(baseline.predict(poly[300:]), targets[300:]))
  • Reservoir(register, device, window=, segment=) builds the program; features(inputs) runs it, exactly or with shots=. A series gives every sliding window.

  • Ridge(alpha) is ridge regression in closed form: fit(features, targets), then predict(features).

  • poly_features(windows, degree) gives every product of a window’s inputs up to degree, the baseline any reservoir should be compared with.

  • narma2(length, seed=), windows(series, window) and nmse(prediction, target) complete the task.

On NARMA2 the reservoir beats a plain linear model but loses to simple polynomial features, so no quantum benefit is claimed (the evidence).

IQP circuits and kernels (iqp, the qiskit extra)#

An IQP circuit encodes a data point in the phases of a layer of commuting gates. The overlap between the states of two points, the fidelity kernel, can then feed a kernel method such as a support vector machine. iqp builds these circuits with Qiskit, on the pairs of atoms close enough for a CZ gate, and computes the kernel on cosmiq’s digital path. It needs pip install "cosmiq[qiskit]".

import numpy as np

import cosmiq as cq
from cosmiq.library import iqp

feature_map = iqp.zz_map(cq.Register.chain(4, 5.0), reps=2)  # one feature per atom
X = np.random.default_rng(1).uniform(0.0, 1.0, size=(5, 4))
K = iqp.kernel(X, feature_map=feature_map)  # [5, 5], exact
K_shots = iqp.kernel(X, feature_map=feature_map, shots=10_000, seed=1)  # estimated from shots
  • iqp.zz_map, iqp.iqp_map and iqp.random_map are Qiskit’s ZZ feature map, IQP circuit and random IQP circuit, with their two-qubit terms only on the register’s CZ pairs (iqp.cz_pairs). Each is transpiled to the device without any SWAP.

  • iqp.probabilities(feature_map, values) gives the circuit’s output distribution, without noise.

  • iqp.kernel(x1, x2=None, feature_map=) gives the kernel matrix between two sets of points: exact, or with shots= estimated from the share of all-zero outcomes, as hardware would measure it.

Refusals#

Code

Kind

Refuses

LIB_MARGIN

INVALID

atoms whose graph isn’t clean at the drive’s strength (a pair neither clearly joined nor clearly apart), or a program driven at another strength than its graph was built for

LIB_SIZE

LIMIT

exact_size, count_sets or report above 24 vertices

LIB_CZ_GRAPH

NOT_IMPLEMENTED

an IQP interaction between atoms too far apart for a CZ

The digital path’s own refusals (DIGITAL_DEVICE, DIGITAL_SIZE and the rest) apply to iqp.

Where the methods come from#

Method

Basis

MIS on the unit-disk graph

Pichler et al. 2018; Ebadi et al. 2022

The reservoir

Fujii & Nakajima 2017; Bravo et al. 2022

NARMA

Atiya & Parlos 2000

IQP and the ZZ feature map

Qiskit’s own circuits

Limits#

No quantum benefit is claimed, for any method. Not built yet: an embedder for arbitrary graphs, weighted MIS, QAOA, graph kernels, and the reservoir on the virtual QPU. What was tested, and how, is in Claims and limits.