MyQLMConverter

class perceval_interop.myqlm.myqlm_converter.MyQLMConverter

myQLM quantum circuit to perceval circuit converter.

convert(gate_circuit, use_postselection=True)

Convert a gate-based quantum circuit into an Experiment.

Parameters:
  • gate_circuit – gate-based quantum circuit (Qiskit, Myqlm or CQASM)

  • use_postselection (bool) – when True (default), uses optimized number of postprocessed CNOT and Heralded CNOT gates. Otherwise, uses only heralded CNOT.

Return type:

Experiment

Returns:

the converted experiment

MyQLMCommunicationLayer

class perceval_interop.myqlm.myqlm_communication_layer.MyQLMCommunicationLayer(remote_qpu)
cancel(remote_id)

Request cancellation of a remote job.

The request need not make cancellation immediate; later calls to get_job_status() communicate the final state.

Parameters:

remote_id (_LocalId | AsyncResult) – Identifier returned by send().

Return type:

None

delete_session()

Permanently delete the current provider session.

Stateless implementations may keep the default no-op implementation.

Return type:

None

get_availability()

Return the number of concurrent jobs that can currently be submitted by the user.

Return 0 when the provider has no free capacity or availability cannot be established. Always returns 1 if there is no API call to get this number. The value must not be negative.

Return type:

int

get_commands()

Return the commands implemented by the remote platform.

Each command name must identify an operation that the provider can execute, and its signature must describe the parameters accepted by that operation.

Return type:

list[Command]

get_job_status(remote_id, refresh_errors=0)

Retrieve the current status of a remote job.

Returning None signals a transient refresh failure. RemoteComputer keeps the previous status and passes the number of consecutive failures back on the next call, so an implementation can eventually raise a permanent error.

Parameters:
  • remote_id (_LocalId | AsyncResult) – Identifier returned by send().

  • refresh_errors (int) – Number of consecutive previous calls that returned None.

Return type:

Optional[ExecutionStatus]

Returns:

The current execution status, or None after a recoverable refresh failure.

get_performances()

Return the platform performance characterization.

The mapping is exposed as RemoteComputer.performance and may also be used to derive its noise model.

Return type:

dict

get_platform_details()

Return any kind of information that the platform could provide. No particular field is guaranteed to exist here, nor do their types. This should only be used for information purpose or on specific computers, and always check that the read field exists before accessing it.

Return type:

dict

get_remote_status()

Return the provider’s current platform status as a human-readable string.

Return type:

str

get_results(remote_id)

Retrieve the results of a completed remote job.

Parameters:

remote_id (_LocalId | AsyncResult) – Identifier returned by send().

Return type:

dict

Returns:

A Perceval result dictionary, normally containing "results" or "results_list" and any associated performance data.

Raises:

Exception – If the provider cannot retrieve the results.

get_specs()

Return the capabilities and constraints of the target platform.

Return type:

PlatformSpecs

Returns:

The target platform specifications.

property name: str

The name of the remote platform.

send(payload)

Submit a Perceval payload to the remote platform.

The payload is produced by PayloadGenerator and contains a Computation or ComputationIterator, plus optional noise, mitigation, and computer-specific parameters. An implementation is responsible for translating or serializing it into its provider’s request format.

Parameters:

payload (dict) – The payload to submit.

Return type:

_LocalId | AsyncResult

Returns:

A provider-defined, stable job identifier accepted by the other job methods.

start_session()

Start or acquire a provider session.

Stateless implementations may keep the default no-op implementation.

Return type:

None

stop_session()

Stop or release the current provider session without deleting it.

Stateless implementations may keep the default no-op implementation.

Return type:

None

QuandelaQPUHandler

class perceval_interop.myqlm.qpu_handler.QuandelaQPUHandler(computer, sleep_time=1.0)

Quandela compatible version of myQLM QPUHandler class.

Parameters:

computer (AComputer) – A constructed Perceval computer (local or remote)

This class can be used in two ways:

  • As an object

  • As a server

Usage as an object:

>>> from perceval_interop import QuandelaQPUHandler
>>> from perceval import RemoteProcessor
>>> from qat.core import Job
>>>
>>> myqlm_job = Job()
>>> # Define your quantum experiment in the job
>>> # ...
>>> rc = RemoteComputer(QuandelaCommunicationLayer("platform:name", "valid_access_token", "address.of.the.qpu.api"))
>>> handler = QuandelaQPUHandler(rc)
>>> myqlm_result = handler.submit_job(myqlm_job)

Usage as a server:

>>> from perceval import RemoteProcessor
>>> from perceval_interop import QuandelaQPUHandler
>>>
>>> lc = SimulatedComputer("SLOS")
>>> handler = QuandelaQPUHandler(lc)
>>> handler.serve(host_ip="middleware.host.address", port=1212)

After that, the QuandelaQPUHandler is listening to requests and transmitting them to the Quandela platform. User scripts may connect by running:

>>> from qat.qpus import RemoteQPU
>>> from qat.core import Job
>>>
>>> myqlm_job = Job()
>>> # Define your quantum experiment in the job
>>> # ...
>>> qpu = RemoteQPU(1212, "middleware.host.address")
>>> result = qpu.submit_job(myqlm_job)
classmethod addargs(parser)

Add arguments to a parser

apply_resource_consumption_limits(allocation_model)

Placeholder: subclasses must implement this

compile(batch)

Loops a batch through all the plugins present inside the QPU.

Return type:

Batch

Args:
batch (Batch): a batch of jobs. If a single job is provided, the

job is embedded into a Batch, compiled, and the first result is returned.

Return:

Batch: a batch of jobs

estimate_resources_for_batch(batch)

Placeholder: subclasses must implement this.

QPU classes implement this method to locally compute a list of ResourceModel which tells what resources they will need to compute a batch.

Return type:

List[ResourceModel]

get_specs()

Retrieve the specifications of the Quandela platform and store them in the metadata field of a myQLM HardwareSpecs instance.

Return type:

HardwareSpecs

Returns:

Hardware specifications

Data is split into several chunks (some are optional, depending on the platform):

  • Full specifications
    • Available commands

    • Chip architecture

    • Platform custom options

    • Platform documentation

  • Platform type

  • Latest auto-characterisation results (QPU performance - in terms of transmittance, g², HOM, etc.)

  • Platform status (available, running, in maintenance…)

  • Current job progress (float between 0 and 1, 1 meaning 100% or no job running)

post_process(results)

Loops back Results through all the Plugin stack.

Return type:

BatchResult

Args:

results (BatchResult): a list of Results

Return:

(BatchResult): a list of Results

push_plugin(plugin)

Adds a plugin in front of the plugin stack.

Warning

This function is deprecated, use instead the | operator. The line QPU.push_plugin(plugin) should be replaced by QPU = plugin | QPU.

Args:

plugin(qat.plugins.AbstractPlugin) : a plugin

serve(port, host_ip='localhost', server_type=None, ssl_cert=None, ssl_key=None, ssl_ca=None)

Runs the QPU inside a server, optionally with the SSL protocol.

Args:

port(int): the port on which to listen host_ip(str): the url on which to publish the API. Optional.

Defaults to ‘localhost’.

server_type (str, optional): type of server. The different

types of server are:

  • “simple”: single-thread server, accepts one connection at a time (default server type)

  • “threaded”: multi-thread server, each connection starts a new thread

  • “pool”: multi-thread server, each connection runs in a thread, with a maximum of 10 running threads

  • “fork”: multi-process server, each connection runs in a new process (UNIX-only)

  • “stoppable”: custom server based on “fork”, but server processes will be killed after a keepalive timeout is reached (UNIX-only)

ssl_cert (str, optional): path to the server SSL certificate (mandatory for SSL)

Default: None

ssl_key (str, optional): path to the server SSL key (mandatory for SSL)

Default: None

ssl_ca (str, optional): path to the server SSL certificate authority

(only serves requests with signed certificates) Default: None

submit(batch, meta_data=None)

Executes a batch of jobs and returns the corresponding list of Results.

Return type:

BatchResult

Args:
batch (Batch): a batch of jobs. If a single job is provided, the

job is embedded into a Batch, executed, and the first result is returned.

Return:

(BatchResult): a batch result

submit_job(job)

Submit a myQLM job to the Quandela platform.

Parameters:

job (Job) –

A myQLM Job containing

  • either a photonic-compatible gate-based circuit

  • or a Perceval generated payload, stored in the job metadata

Return type:

Result

Returns:

A myQLM Result containing Perceval-like results in its metadata field

static wrap_result(job, res)

Wrap a Result structure using the corresponding Job’s information This is mainly to provide a cleaner/higher level interface for the user

MyQLMSession

Warning

This class is for the legacy perceval workflow.

class perceval_interop.myqlm.myqlm_session.MyQLMSession(remote_qpu)

Automatic translator allowing to use a MyQLM RemoteQPU as if it was a perceval RemoteProcessor.

There are a few things that a RemoteProcessor generated by this class can’t do, such as:

  • Being used in a JobGroup

  • Retrieving a job from its id (so a job is lost forever if python stops)

  • Some advanced job methods (rerun…)

  • Jobs will always be executed synchronously

Usage:

>>> from perceval_interop import MyQLMSession
>>> from qat.core.qpu import RemoteQPU
>>> remote_qpu = RemoteQPU(1212, "middleware.host.address")  # Assuming this is a remote QuandelaQPUHandler
>>> session = MyQLMSession(remote_qpu)
>>> processor = session.build_remote_processor()
>>> # You can now proceed with the processor as if it was any perceval RemoteProcessor.

The import can also be done through perceval’s ProviderFactory:

>>> import perceval_interop  # Needed to add the MyQLM Session to the providers list used by the factory
>>> from perceval import ProviderFactory
>>> from qat.core.qpu import RemoteQPU
>>> remote_qpu = RemoteQPU(1212, "middleware.host.address")  # Assuming this is a remote QuandelaQPUHandler
>>> session = ProviderFactory.get_provider("MyQLM", remote_qpu=remote_qpu)
build_remote_processor()

Build a RemoteProcessor object given the session data

start()

Start session

stop()

Stop session

MyQLMHelper

class perceval_interop.myqlm.myqlm_helper.MyQLMHelper

Helper class that allows to create MyQLM jobs containing perceval experiments so they could run on a QuandelaQPUHandler. This class also converts results from a MyQLM job back to a perceval result object.

Usage example with a local QuandelaQPUHandler:

>>> from perceval import Experiment
>>> from perceval_interop import MyQLMHelper
>>> e = Experiment(4)
>>> ...  # Define your perceval Experiment
>>> my_qlm_job = MyQLMHelper.make_job("sample_count", e, max_samples=1000)
>>> my_qlm_results = qpu_handler.submit_job(my_qlm_job)  # Where qpu_handler is a QuandelaQPUHandler
>>> results = MyQLMHelper.retrieve_results(my_qlm_results)  # Regular results as in any perceval's Sampler results

Usage example with a remote QuandelaQPUHandler:

>>> from perceval import Experiment
>>> from perceval_interop import MyQLMHelper
>>> from qat.qpus import RemoteQPU
>>> e = Experiment(4)
>>> ...  # Define your perceval Experiment
>>> my_qlm_job = MyQLMHelper.make_job("sample_count", e, max_samples=1000)
>>> qpu = RemoteQPU(1212, "middleware.host.address")  # Assuming this is a remote QuandelaQPUHandler
>>> my_qlm_results = qpu.submit_job(myqlm_job)
>>> results = MyQLMHelper.retrieve_results(my_qlm_results)  # Regular results as in any perceval's Sampler results
static make_job(command, experiment, params=None, platform_name='', **kwargs)

Create a myQLM Job from Perceval data

Parameters:
  • command (str) – name of the method used

  • experiment (Experiment) – Perceval experiment

  • params (dict[str, Any]) – (optional) parameters to be listed in the ‘parameters’ section of the payload

  • platform_name (str) – (optional) name of the platform used

  • kwargs – (optional) arguments to add to the payload, such as max_shots or max_samples

Return type:

Job

Returns:

A MyQLM Job instance containing the perceval payload as a string in the meta_data field.

static retrieve_availability(hw)
>>> from perceval_interop import MyQLMHelper
>>> from qat.qpus import RemoteQPU
>>> qpu = RemoteQPU(1212, "middleware.host.address")  # Assuming this is a remote QuandelaQPUHandler
>>> hardware_specs = qpu.get_specs()
>>> availability = MyQLMHelper.retrieve_availability(hardware_specs)
Parameters:

hw (HardwareSpecs) – A HardwareSpecs instance got from requesting the specs from a Quandela QPU

Return type:

int

Returns:

The number of parallel jobs that can currently be launched to the QPU, or 1 if the Hardware specs don’t contain this information

classmethod retrieve_details(hw)
>>> from perceval_interop import MyQLMHelper
>>> from qat.qpus import RemoteQPU
>>> qpu = RemoteQPU(1212, "middleware.host.address")  # Assuming this is a remote QuandelaQPUHandler
>>> hardware_specs = qpu.get_specs()
>>> availability = MyQLMHelper.retrieve_availability(hardware_specs)
Parameters:

hw (HardwareSpecs) – A HardwareSpecs instance got from requesting the specs from a Quandela QPU

Return type:

dict[str, Any]

Returns:

The number of parallel jobs that can currently be launched to the QPU, or 1 if the Hardware specs don’t contain this information

static retrieve_job_in_queue(hw)
>>> from perceval_interop import MyQLMHelper
>>> from qat.qpus import RemoteQPU
>>> qpu = RemoteQPU(1212, "middleware.host.address")  # Assuming this is a remote QuandelaQPUHandler
>>> hardware_specs = qpu.get_specs()
>>> job_in_queue = MyQLMHelper.retrieve_status(hardware_specs)
Parameters:

hw (HardwareSpecs) – A HardwareSpecs instance got from requesting the specs from a Quandela QPU

Return type:

dict

Returns:

The number of jobs currently in queue on the QPU, or None if the Hardware specs don’t contain this information

static retrieve_name(hw)
>>> from perceval_interop import MyQLMHelper
>>> from qat.qpus import RemoteQPU
>>> qpu = RemoteQPU(1212, "middleware.host.address")  # Assuming this is a remote QuandelaQPUHandler
>>> hardware_specs = qpu.get_specs()
>>> remote_name = MyQLMHelper.retrieve_name(hardware_specs)
Parameters:

hw (HardwareSpecs) – A HardwareSpecs instance got from requesting the specs from a Quandela QPU

Return type:

str

Returns:

The name of the perceval computer contained in the QPU, or an empty string if the Hardware specs don’t contain this information

static retrieve_perf(hw)
>>> from perceval_interop import MyQLMHelper
>>> from qat.qpus import RemoteQPU
>>> qpu = RemoteQPU(1212, "middleware.host.address")  # Assuming this is a remote QuandelaQPUHandler
>>> hardware_specs = qpu.get_specs()
>>> performances = MyQLMHelper.retrieve_perf(hardware_specs)
Parameters:

hw (HardwareSpecs) – A HardwareSpecs instance got from requesting the specs from a Quandela QPU

Return type:

dict

Returns:

The performances of the QPU, as if returned by a perceval’s RemoteProcessor

static retrieve_progress(hw)
>>> from perceval_interop import MyQLMHelper
>>> from qat.qpus import RemoteQPU
>>> qpu = RemoteQPU(1212, "middleware.host.address")  # Assuming this is a remote QuandelaQPUHandler
>>> hardware_specs = qpu.get_specs()
>>> progress = MyQLMHelper.retrieve_progress(hardware_specs)
Parameters:

hw (HardwareSpecs) – A HardwareSpecs instance got from requesting the specs from a Quandela QPU

Return type:

dict

Returns:

The progress of the current job running on the QPU

static retrieve_results(results)
>>> from perceval_interop import MyQLMHelper
>>> myqlm_result = qpu.submit_job(myqlm_job)
>>> results = MyQLMHelper.retrieve_results(myqlm_result)
Parameters:

results (Result | AsyncResult) – A MyQLM Result instance got from running a MyQLM job on a local or remote QuandelaQPU.

Return type:

dict

Returns:

The specs of the QPU, as if returned by a perceval’s RemoteProcessor

static retrieve_specs(hw)
>>> from perceval_interop import MyQLMHelper
>>> from qat.qpus import RemoteQPU
>>> qpu = RemoteQPU(1212, "middleware.host.address")  # Assuming this is a remote QuandelaQPUHandler
>>> hardware_specs = qpu.get_specs()
>>> qpu_specs = MyQLMHelper.retrieve_specs(hardware_specs)
Parameters:

hw (HardwareSpecs) – A HardwareSpecs instance got from requesting the specs from a Quandela QPU

Return type:

dict

Returns:

The specs of the QPU, as if returned by a perceval’s RemoteProcessor

static retrieve_status(hw)
>>> from perceval_interop import MyQLMHelper
>>> from qat.qpus import RemoteQPU
>>> qpu = RemoteQPU(1212, "middleware.host.address")  # Assuming this is a remote QuandelaQPUHandler
>>> hardware_specs = qpu.get_specs()
>>> status = MyQLMHelper.retrieve_status(hardware_specs)
Parameters:

hw (HardwareSpecs) – A HardwareSpecs instance got from requesting the specs from a Quandela QPU

Return type:

str

Returns:

The status of the QPU, as if returned by a perceval’s RemoteProcessor

static retrieve_type(hw)
>>> from perceval_interop import MyQLMHelper
>>> from qat.qpus import RemoteQPU
>>> qpu = RemoteQPU(1212, "middleware.host.address")  # Assuming this is a remote QuandelaQPUHandler
>>> hardware_specs = qpu.get_specs()
>>> qpu_type = MyQLMHelper.retrieve_type(hardware_specs)
Parameters:

hw (HardwareSpecs) – A HardwareSpecs instance got from requesting the specs from a Quandela QPU

Return type:

str

Returns:

The type of the QPU (physical or simulator)