MyQLMConverter
- class perceval_interop.myqlm.myqlm_converter.MyQLMConverter(backend_name='SLOS', noise_model=None)
myQLM quantum circuit to perceval circuit converter.
- Parameters:
backend_name (
str
) – Backend to use in computation, defaults to SLOS
- convert(gate_circuit, use_postselection=True)
Convert a gate-based quantum circuit into a Processor.
- 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:
Processor
- Returns:
the converted processor
QuandelaQPUHandler
- class perceval_interop.myqlm.qpu_handler.QuandelaQPUHandler(remote_processor)
Quandela compatible version of myQLM
QPUHandler
class. This class is supposed to be the middleware between a user script, or a Qaptiva server and a single remote platform from Quandela.- Parameters:
remote_processor (
RemoteProcessor
) – A constructed Perceval access to a remote platform which will be used to send requests and retrieve results.
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 >>> # ... >>> rp = RemoteProcessor("platform:name", "valid_access_token", "address.of.the.qpu.api") >>> handler = QuandelaQPUHandler(rp) >>> myqlm_result = handler.submit_job(myqlm_job)
Usage as a server:
>>> from perceval import RemoteProcessor >>> from perceval_interop import QuandelaQPUHandler >>> >>> rp = RemoteProcessor("platform:name", "valid_access_token", "address.of.the.qpu.api") >>> handler = QuandelaQPUHandler(rp) >>> 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.
- batch (
- 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 name
Latest auto-characterisation results (QPU performance - in terms of transmittance, g², HOM, etc.)
- 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 lineQPU.push_plugin(plugin)
should be replaced byQPU = 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
- 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.
- batch (
- Return:
(
BatchResult
): a batch result
- submit_job(job)
Submit a myQLM job to the Quandela platform.
- Parameters:
job (
Job
) –A myQLM
Job
containingeither 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
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 usedexperiment (
Experiment
) – Perceval experimentparams (
Optional
[dict
[str
,any
]]) – (optional) parameters to be listed in the ‘parameters’ section of the payloadplatform_name (
str
) – (optional) name of the platform usedkwargs – (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_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_results(results)
>>> from perceval_interop import MyQLMHelper >>> myqlm_result = qpu.submit_job(myqlm_job) >>> results = MyQLMHelper.retrieve_results(myqlm_result)
- Parameters:
results (
Result
) – 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_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)