This release is a pre-release and may not be stable for production use.
quapp-merlin
Quapp provider lib for MerLin, Quandela's photonic quantum machine learning framework. MerLin wraps Perceval but is a separate SDK here: a MerLin handler returns a PyTorch model, not a circuit.
SDK tag: MERLIN · providers: QUAO_QUANTUM_SIMULATOR (local), QUANDELA (cloud)
What a handler returns
Every other SDK on the platform has processing() return a circuit. MerLin has
no circuit to return -- the unit of work is a torch.nn.Module holding a
merlin.QuantumLayer, plus the batch to run it on.
import merlin as ML
import torch
from quapp_merlin import MerlinJobSpec
def processing(invocation_input: dict) -> MerlinJobSpec:
layer = ML.QuantumLayer.simple(
input_size=4,
measurement_strategy=ML.MeasurementStrategy.probs())
return MerlinJobSpec(model=layer,
inputs=torch.tensor(invocation_input['inputs']),
shots=invocation_input.get('shots'))
def post_processing(job_result: dict) -> dict:
return {'probabilities': job_result['result']['values']}
Returning a bare torch.nn.Module also works, and the batch is then read from
invocation_input["inputs"].
shots=None (the default) means exact probabilities: MerLin does not invent
a shot count, and neither does this lib.
One invocation, one machine
MerLin fans out along three axes, and the first one can put a job on a machine nobody selected:
| Axis | What it does | Rule here |
|---|---|---|
| Backend | one MerlinProcessor binds one backend, but a handler can build a second one and route layers to it |
refused -- the machine comes from DeviceSelection |
| Chunks | len(X) > microbatch_size splits a batch into several cloud jobs |
chunk_concurrency=1, batch must fit one microbatch |
| Leaves | several QuantumLayers in one model, each its own remote job |
one layer per invocation |
Together these keep future.job_ids a single id, so provider_job_id stays one
value the backend can store as-is. The rules live in
quapp_merlin/util/single_machine.py and are locked by
tests/test_single_machine.py.
Local vs remote
local (QUAO_QUANTUM_SIMULATOR) |
remote (QUANDELA) |
|
|---|---|---|
| Runs on | SLOS simulation in the container, CPU only | Quandela Cloud, sim:* or qpu:* |
| Training | yes, MerlinJobSpec(training=TrainingSpec(...)) |
no -- no gradient flows through the MerLin processor |
| Phases | COMPILATION, EXECUTION, ANALYSIS | plus POLLING while waiting on the cloud |
| Job id | none | one, from future.job_ids |
The image ships the CPU build of torch on purpose: the default wheel drags in
the whole CUDA runtime (~2.5 GB) for a photonic simulator that never touches a
GPU. A job asking for ProcessingUnit.GPU runs on CPU with a warning.
Result shape
_create_job returns a dict that is already JSON-safe -- no tensor ever reaches
json.dumps in a callback:
{'result': {'values': [[0.24, 0.76]], 'truncated': False, 'elements': 2},
'shape': [1, 2],
'batch_size': 1,
'shots': None,
'measurement': 'probs',
'execution_time': 0.184,
'provider_job_id': None,
'histogram': {'state_0': 0.24, 'state_1': 0.76},
'metadata': {}}
histogram is only produced for a probability measurement of a single row: with
a batch there are as many distributions as rows, and with
mode_expectations() / amplitudes() there is no distribution over states to
bin. It is None in those cases, and the full output stays in result.
Large outputs are truncated with truncated: True and the real element count,
rather than silently sending the first rows as if they were everything.
Versions
merlinquantum |
==0.4.1 -- 0.4 renamed the QuantumLayer arguments 0.3 used (output_mapping_strategy -> measurement_strategy, ansatz -> builder), so >= would break every handler |
quapp-common |
==0.0.15.dev5 -- first release carrying Sdk.MERLIN |
| Python | >=3.10 (merlinquantum), <3.15 (perceval-quandela) |
import quapp_merlin needs none of torch, merlin or perceval: every SDK import
sits inside the function that uses it, so the error classifier still works in an
image where the SDK failed to install. tests/test_lazy_sdk_imports.py enforces
it.
Metadata
Release files for quapp-merlin 0.0.1.dev3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| quapp_merlin-0.0.1.dev3.tar.gz | 40.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| quapp_merlin-0.0.1.dev3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 72.6 kB
Release files / quapp_merlin-0.0.1.dev3.tar.gz
| Download URL | quapp_merlin-0.0.1.dev3.tar.gz |
|---|---|
| Size | 40.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1b8a5990994f1812af33ec9414e04e50090f3f77a6f6a610f1188e48efd1ac79
|
|
BLAKE2b-256 checksum How to use checksums |
f160019cded62746a133504f024fb0c6f6619285f66fec4ba778f18f3d655736
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.12
|
Release files / quapp_merlin-0.0.1.dev3-py3-none-any.whl
| Download URL | quapp_merlin-0.0.1.dev3-py3-none-any.whl |
|---|---|
| Size | 32.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9387dbfc70c2771073e3f0111a1e216a96e7cbfe1e73dcf7e59b5c74412ec281
|
|
BLAKE2b-256 checksum How to use checksums |
8bbf05dbdf548228ebc070780ea84cb703b6e63d2dd8b683197d70a361904ede
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.12
|