Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion perceval/algorithm/abstract_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from perceval.runtime.abstract_processor import AProcessor
from perceval.runtime import AProcessor


class AAlgorithm:
Expand Down
5 changes: 2 additions & 3 deletions perceval/algorithm/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
sample_count_to_probs, probs_to_samples, probs_to_sample_count, ProgressCallback
from perceval.utils.logging import get_logger, channel
from perceval.utils.constants import KEY_MAX_SHOTS, KEY_MAX_SAMPLES, KEY_RESULTS_LIST, KEY_ITERATION
from perceval.runtime.parameter_iterator import ParameterIterator
from perceval.runtime.abstract_processor import AProcessor
from perceval.runtime import Job, RemoteJob, LocalJob
from perceval.runtime.legacy.parameter_iterator import ParameterIterator
from perceval.runtime.legacy import Job, RemoteJob, LocalJob, AProcessor


class Sampler(AAlgorithm):
Expand Down
2 changes: 1 addition & 1 deletion perceval/components/_mode_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, left_experiment, right_obj, mapping):
:param right_obj: the component or processor to plug on the right of `left_experiment`
:param mapping: the user mapping defining the plugging rules (see resolve method doc for more info)
"""
from perceval.runtime.abstract_processor import AProcessor
from perceval.runtime.legacy.abstract_processor import AProcessor # TODO: deprecated 1.3
if isinstance(left_experiment, AProcessor):
left_experiment = left_experiment.experiment
self._le = left_experiment
Expand Down
4 changes: 2 additions & 2 deletions perceval/components/feed_forward_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class FFCircuitProvider(AFFConfigurator):
def __init__(self, m: int, offset: int, default_circuit: ACircuit, name: str = None):
assert not isinstance(default_circuit, AFFConfigurator), \
"Can't add directly a Feed-forward configurator to a configurator (use an Experiment)"
from perceval.runtime.abstract_processor import AProcessor
from perceval.runtime.legacy.abstract_processor import AProcessor
if isinstance(default_circuit, AProcessor):
default_circuit = default_circuit.experiment
super().__init__(m, offset, default_circuit, name)
Expand Down Expand Up @@ -171,7 +171,7 @@ def add_configuration(self, state, circuit: ACircuit) -> FFCircuitProvider:
if circuit.m != self._max_circuit_size:
raise RuntimeError(f"Circuit size mismatch (got {circuit.m}, expected {self._max_circuit_size} modes)")

from perceval.runtime.abstract_processor import AProcessor
from perceval.runtime.legacy.abstract_processor import AProcessor
if isinstance(circuit, AProcessor):
circuit = circuit.experiment

Expand Down
8 changes: 4 additions & 4 deletions perceval/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
# SOFTWARE.
"""Provider related imports and classes"""

from perceval.runtime import ISession
from perceval.runtime.legacy import ISession

from .quandela import Session as QuandelaSession
from .scaleway import Session as ScalewaySession
from .kipu import Session as KipuSession
from .quandela import Session as QuandelaSession, QuandelaCommunicationLayer
from .scaleway import Session as ScalewaySession, ScalewayCommunicationLayer
from .kipu import Session as KipuSession, KipuCommunicationLayer

PROVIDER_LIST = {
"Quandela": QuandelaSession,
Expand Down
32 changes: 30 additions & 2 deletions perceval/providers/kipu/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# MIT License
#
# Copyright (c) 2022 Quandela
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# As a special exception, the copyright holders of exqalibur library give you
# permission to combine exqalibur with code included in the standard release of
# Perceval under the MIT license (or modified versions of such code). You may
# copy and distribute such a combined system following the terms of the MIT
# license for both exqalibur and Perceval. This exception for the usage of
# exqalibur is limited to the python bindings used by Perceval.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# MIT License
#
# Copyright (c) 2026 Kipu Quantum GmbH
Expand Down Expand Up @@ -29,5 +58,4 @@

from .kipu_session import Session
from .kipu_rpc_handler import KipuRPCHandler

__all__ = ["Session", "KipuRPCHandler"]
from .kipu_communication_layer import KipuCommunicationLayer
53 changes: 53 additions & 0 deletions perceval/providers/kipu/kipu_communication_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# MIT License
#
# Copyright (c) 2022 Quandela
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# As a special exception, the copyright holders of exqalibur library give you
# permission to combine exqalibur with code included in the standard release of
# Perceval under the MIT license (or modified versions of such code). You may
# copy and distribute such a combined system following the terms of the MIT
# license for both exqalibur and Perceval. This exception for the usage of
# exqalibur is limited to the python bindings used by Perceval.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from perceval.runtime.communication_layer import RPCBasedCommunicationLayer

from perceval.utils.logging import get_logger, channel

from .kipu_rpc_handler import KipuRPCHandler


class KipuCommunicationLayer(RPCBasedCommunicationLayer):

def __init__(self,
platform_name: str,
token: str = None,
organization_id: str = None,
url: str = None,
proxies: dict = None):

super().__init__(KipuRPCHandler(
platform_name=platform_name,
url=url,
token=token,
organization_id=organization_id,
proxies=proxies,
))

get_logger().info(f"Connected to Kipu Cloud platform {platform_name}", channel.general)
14 changes: 9 additions & 5 deletions perceval/providers/kipu/kipu_rpc_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# SKIP LICENSE INSERTION

# MIT License
#
# Copyright (c) 2026 Kipu Quantum GmbH
Expand Down Expand Up @@ -29,6 +31,8 @@

from datetime import datetime

from perceval.utils.constants import KEY_VERSION, KEY_PROCESS_ID, KEY_JOB_NAME, KEY_MAX_SHOTS, KEY_MAX_SAMPLES, KEY_PAYLOAD

_MISSING_QHUB_MSG = (
"The Kipu Quantum Hub provider requires the 'qhub-api' package. "
"Install it with: pip install perceval[kipu]"
Expand Down Expand Up @@ -214,8 +218,8 @@ def headers(self) -> dict:
def create_job(self, payload: dict) -> str:
"""Submit a Perceval job payload to the Hub. Returns the Hub job id."""
qhub = _import_qhub()
inner = payload.get("payload") or {}
shots = inner.get("max_shots") or inner.get("max_samples") or 0
inner = payload.get(KEY_PAYLOAD) or {}
shots = inner.get(KEY_MAX_SHOTS) or inner.get(KEY_MAX_SAMPLES) or 0

input_cls = qhub["input"][self._backend_id]
params_cls = qhub["params"][self._backend_id]
Expand All @@ -226,11 +230,11 @@ def create_job(self, payload: dict) -> str:
input=input_cls(value=inner),
input_format="PERCEVAL",
input_params=params_cls(
pcvl_version=payload.get("pcvl_version"),
process_id=payload.get("process_id"),
pcvl_version=payload.get(KEY_VERSION),
process_id=payload.get(KEY_PROCESS_ID),
),
sdk_provider="PERCEVAL",
name=payload.get("job_name"),
name=payload.get(KEY_JOB_NAME),
)
return job.id

Expand Down
5 changes: 3 additions & 2 deletions perceval/providers/kipu/kipu_session.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# SKIP LICENSE INSERTION

# MIT License
#
# Copyright (c) 2026 Kipu Quantum GmbH
Expand Down Expand Up @@ -27,8 +29,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from perceval.runtime import ISession
from perceval.runtime.remote_processor import RemoteProcessor
from perceval.runtime.legacy import ISession, RemoteProcessor
from perceval.utils.logging import get_logger, channel

from .kipu_rpc_handler import KipuRPCHandler
Expand Down
1 change: 1 addition & 0 deletions perceval/providers/quandela/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
# SOFTWARE.

from .quandela_session import Session
from .quandela_communication_layer import QuandelaCommunicationLayer
48 changes: 48 additions & 0 deletions perceval/providers/quandela/quandela_communication_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# MIT License
#
# Copyright (c) 2022 Quandela
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# As a special exception, the copyright holders of exqalibur library give you
# permission to combine exqalibur with code included in the standard release of
# Perceval under the MIT license (or modified versions of such code). You may
# copy and distribute such a combined system following the terms of the MIT
# license for both exqalibur and Perceval. This exception for the usage of
# exqalibur is limited to the python bindings used by Perceval.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from requests import HTTPError

from perceval.runtime.communication_layer import RPCBasedCommunicationLayer
from perceval.utils.logging import get_logger, channel

from .rpc_handler import RPCHandler

class QuandelaCommunicationLayer(RPCBasedCommunicationLayer):

def __init__(self, name: str, token: str, url: str, proxies: dict[str, str] = None):
super().__init__(RPCHandler(name, url, token, proxies))
get_logger().info(f"Connected to Cloud platform {name}", channel.general)

def get_availability(self) -> int:
try:
availability = self._rpc_handler.get_job_availability()
return availability["max_jobs_in_queue"] - availability["num_jobs_in_queue"]
except HTTPError:
get_logger().warn("Impossible to determine whether there is room for a new job")
return 0
5 changes: 2 additions & 3 deletions perceval/providers/quandela/quandela_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from perceval.runtime import ISession
from perceval.runtime.remote_processor import RemoteProcessor
from perceval.runtime.legacy import ISession, RemoteProcessor
from perceval.runtime.remote_config import QUANDELA_CLOUD_URL
from perceval.runtime.rpc_handler import RPCHandler
from perceval.utils.logging import get_logger, channel

from .rpc_handler import RPCHandler

class Session(ISession):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
_JOB_ID_KEY = 'job_id'


# TODO: move this class to providers/quandela
class RPCHandler:
"""Remote Call Procedure Handler

Expand Down Expand Up @@ -127,7 +128,7 @@ def fetch_platform_details(self):
try:
response = self.get_request(endpoint)
# TEMPORARY CODE
# TODO: to be removed in version 1.2
# TODO: to be removed in version 1.3
if 'architecture' not in response.get('specs', {}):
raise requests.HTTPError("Missing required 'architecture' field, falling back to the old endpoint "
"containing the 'specific_circuit' field.")
Expand Down
3 changes: 1 addition & 2 deletions perceval/providers/scaleway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@

from .scaleway_session import Session
from .scaleway_rpc_handler import RPCHandler

__all__ = ["Session", "RPCHandler"]
from .scaleway_communication_layer import ScalewayCommunicationLayer
77 changes: 77 additions & 0 deletions perceval/providers/scaleway/scaleway_communication_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# MIT License
#
# Copyright (c) 2022 Quandela
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# As a special exception, the copyright holders of exqalibur library give you
# permission to combine exqalibur with code included in the standard release of
# Perceval under the MIT license (or modified versions of such code). You may
# copy and distribute such a combined system following the terms of the MIT
# license for both exqalibur and Perceval. This exception for the usage of
# exqalibur is limited to the python bindings used by Perceval.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from perceval.runtime.communication_layer import RPCBasedCommunicationLayer
from perceval.utils.logging import get_logger, channel

from .scaleway_rpc_handler import RPCHandler

class ScalewayCommunicationLayer(RPCBasedCommunicationLayer):

def __init__(self,
platform_name: str,
project_id: str,
token: str,
max_idle_duration_s: int = 1200,
max_duration_s: int = 3600,
deduplication_id: str = None,
url: str = None,
proxies: dict[str, str] = None,
provider_name: str = None):

self._deduplication_id = deduplication_id
self._max_idle_duration_s = max_idle_duration_s
self._max_duration_s = max_duration_s

super().__init__(RPCHandler(
project_id=project_id,
secret_key=token,
url=url,
proxies=proxies,
platform_name=platform_name,
provider_name=provider_name,
))
get_logger().info(f"Connected to Scaleway Cloud platform {platform_name}", channel.general)

def start_session(self) -> None:
self._rpc_handler.create_session(
max_duration_s=self._max_idle_duration_s,
max_idle_duration_s=self._max_idle_duration_s,
deduplication_id=self._deduplication_id,
)

def stop_session(self) -> None:
self._rpc_handler.terminate_session()
get_logger().info("Stop Scaleway Session", channel.general)

def delete_session(self) -> None:
self._rpc_handler.delete_session()
get_logger().info(
"Stop (if not already) and revoke Scaleway Session", channel.general
)
Loading
Loading