Skip to main content

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.17.dev1 -- Sdk.MERLIN exists from 0.0.15.dev5 on; 0.0.15 stable lacks it, so a stable pin needs 0.0.16 or later
perceval-quandela >=1.2.1,<1.3 -- merlinquantum 0.4.1 only asks for >=1.2.1, but it imports perceval.runtime.session, which 1.3.0 removed; without the cap a fresh install fails on import 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

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
File Size Uploaded Provenance Actions
quapp_merlin-0.0.1.tar.gz 40.5 kB Without provenance Details for quapp_merlin-0.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 73.0 kB

Release files / quapp_merlin-0.0.1.tar.gz

Download URL quapp_merlin-0.0.1.tar.gz
Size 40.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a39c06dffa20070e74562dbdf5ae1ec235040b211c2659711e471ee69416dba2
BLAKE2b-256 checksum
How to use checksums
652510543bc17edadcfe68975edfc695795517203b2bff81cd01bd4cfadabf52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / quapp_merlin-0.0.1-py3-none-any.whl

Download URL quapp_merlin-0.0.1-py3-none-any.whl
Size 32.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4447e1b5bc42fc22135c129b921456fe074747029243956b18fca2059ed01563
BLAKE2b-256 checksum
How to use checksums
612733fc6ec45046d7ed0b32dd8aa77ef173be1c788416f2a91b0ae134a12577
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Security for quapp-merlin 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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