Skip to main content
Pre-release

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.dev2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quapp-merlin 0.0.1.dev2
File Size Uploaded
quapp_merlin-0.0.1.dev2.tar.gz 38.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for quapp-merlin 0.0.1.dev2
File Interpreter ABI Platform
quapp_merlin-0.0.1.dev2-py3-none-any.whl Python 3 none any Details

Total release size: 71.0 kB

Release files / quapp_merlin-0.0.1.dev2.tar.gz

Download URL quapp_merlin-0.0.1.dev2.tar.gz
Size 38.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a9f7b61a4b0883fe31f0ce0d198754c22a861cab96f7052cbba4bcec542d9ddc
BLAKE2b-256 checksum
How to use checksums
5b1d8e21d344f25eb515f1e69421ea5236871b9b8d9ae87551ac3bf2b26b476d
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.dev2-py3-none-any.whl

Download URL quapp_merlin-0.0.1.dev2-py3-none-any.whl
Size 32.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7fe4094a2d287b31fe8742b73790260548cdd9fe0bb993ccc2d43f0936889946
BLAKE2b-256 checksum
How to use checksums
8e449912d07cddaf2cbe37295014b1f0bc75bc6346e5cd7d1db7cb6de67cf774
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page