Skip to content

New correlation primitives, solver and image classification demo - #132

Merged
gcattan merged 9 commits into
IBM:mainfrom
toncho11:main
Sep 7, 2026
Merged

New correlation primitives, solver and image classification demo#132
gcattan merged 9 commits into
IBM:mainfrom
toncho11:main

Conversation

@toncho11

@toncho11 toncho11 commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Added new correlation primitives.
Added a new solver that can take advantage of these primitives.
Added a new image classification demo.

The image classification uses p-kit in an elegant way, not just use p-kit in some way! The algorithm uses a PCircuit more than other implementations I tried. It does not give currently the best results compared to some other experiments I did, but it is the right direction and there is space for optimization. The new primitives and solver (used in this image classification demo) can be used by other algorithms and other users/researchers. Calculation speed has been optimized as the first version was impossibly slow. Also note that the training is very fast, but then the inference is slow.

@gcattan gcattan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @toncho11 , just a few comments.
Looks good otherwise, nice addition!

Comment thread p_kit/solver/corr_ann_solver.py Outdated
return m[0] if n_shots == 1 else m
if n_shots == 1:
return all_m[:, 0, :], all_E[:, 0], all_scales
return all_m, all_E, all_scales

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In CaSuDa and Gibbs solver, it returns all_I, all_m and E.
(the order may be inverted).

Worth checking if this breaks annealing.execute

Comment thread p_kit/solver/corr_ann_solver.py Outdated
for name, scale in scales.items():
field += scale * fields[name]
h += scale * comp_h[name]
return -0.5 * np.sum(m * field, axis=1) - m @ h

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sign convention may differ from the existing solvers. Can you check?

tau=0.1, component_schedules=None, block_size=None):
super().__init__(Nt, dt, i0, expected_mean, seed, backend, tau)
if self.backend.xp is not np:
raise NotImplementedError("CorrelationAnnealingSolver currently supports NumpyBackend only")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I just realise that the Gibbs solver itself is probably not compatible with Torch. Let me open follow-up

aligned solve() with the standard p-kit solver return API so it works correctly with annealing.execute()
aligned the reported energy convention with the other p-kit solvers and updated the best-state comparison accordingly

I updated the Fashion-MNIST demo scoring to preserve the same classification semantics with the new energy convention.
@gcattan
gcattan merged commit 911ea74 into IBM:main Sep 7, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants