Skip to content

Commit 475a2d7

Browse files
authored
Support private jobs on new platform and add job.private property (#2263)
* support private jobs on new platform & add job.private * add reno * address comments * remove print * types * use proper backend * clarify docs
1 parent 37c44f7 commit 475a2d7

File tree

7 files changed

+34
-18
lines changed

7 files changed

+34
-18
lines changed

qiskit_ibm_runtime/base_runtime_job.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(
6767
session_id: Optional[str] = None,
6868
tags: Optional[List] = None,
6969
version: Optional[int] = None,
70+
private: Optional[bool] = False,
7071
) -> None:
7172
"""RuntimeJob constructor.
7273
@@ -84,6 +85,7 @@ def __init__(
8485
session_id: Job ID of the first job in a runtime session.
8586
tags: Tags assigned to the job.
8687
version: Primitive version.
88+
private: Marks job as private.
8789
"""
8890
self._backend = backend
8991
self._job_id = job_id
@@ -101,6 +103,7 @@ def __init__(
101103
self._version = version
102104
self._queue_info: QueueInfo = None
103105
self._status: Union[RuntimeJobStatus, str] = None
106+
self._private = private
104107

105108
decoder = result_decoder or DEFAULT_DECODERS.get(program_id, None) or ResultDecoder
106109
if isinstance(decoder, Sequence):
@@ -116,6 +119,11 @@ def __init__(
116119
"results streaming was removed in a previous release.",
117120
)
118121

122+
@property
123+
def private(self) -> bool:
124+
"""Returns a boolean indicating whether or not the job is private."""
125+
return self._private
126+
119127
def job_id(self) -> str:
120128
"""Return a unique id identifying the job."""
121129
return self._job_id

qiskit_ibm_runtime/options/environment_options.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ class EnvironmentOptions:
5252
Default: ``None``.
5353
"""
5454
private: Optional[bool] = False
55-
r"""Boolean that indicates whether the job is marked as private. This is only
56-
supported for ``ibm_quantum`` channel. When set to true, input parameters are not
57-
returned, and the results can only be read once. After the results are read or after
58-
a specified time after the job is completed, the results are deleted from the service.
59-
When set to false, the input parameters and results follow the standard retention
60-
behavior.
55+
r"""Boolean that indicates whether the job is marked as private. When set to true,
56+
input parameters are not returned, and the results can only be read once.
57+
After the job is completed, input parameters are deleted from the service.
58+
After the results are read, these are also deleted from the service.
59+
When set to false, the input parameters and results follow the
60+
standard retention behavior of the API.
6161
6262
Default: False.
6363
"""

qiskit_ibm_runtime/qiskit_runtime_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ def _run(
893893
image=qrt_options.image,
894894
service=self,
895895
version=version,
896+
private=qrt_options.private,
896897
)
897898

898899
def check_pending_jobs(self) -> None:
@@ -1136,6 +1137,7 @@ def _decode_job(self, raw_data: Dict) -> Union[RuntimeJob, RuntimeJobV2]:
11361137
image=raw_data.get("runtime"),
11371138
session_id=raw_data.get("session_id"),
11381139
tags=raw_data.get("tags"),
1140+
private=raw_data.get("private", False),
11391141
)
11401142

11411143
def least_busy(

qiskit_ibm_runtime/runtime_job_v2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def __init__(
7070
session_id: Optional[str] = None,
7171
tags: Optional[List] = None,
7272
version: Optional[int] = None,
73+
private: Optional[bool] = False,
7374
) -> None:
7475
"""RuntimeJob constructor.
7576
@@ -87,6 +88,7 @@ def __init__(
8788
session_id: Job ID of the first job in a runtime session.
8889
tags: Tags assigned to the job.
8990
version: Primitive version.
91+
private: Marks job as private.
9092
"""
9193
BasePrimitiveJob.__init__(self, job_id=job_id)
9294
BaseRuntimeJob.__init__(
@@ -104,6 +106,7 @@ def __init__(
104106
session_id=session_id,
105107
tags=tags,
106108
version=version,
109+
private=private,
107110
)
108111
self._status: JobStatus = "INITIALIZING"
109112

qiskit_ibm_runtime/runtime_options.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ def __init__(
7070
this time limit, it is forcibly cancelled. Simulator jobs continue to use wall
7171
clock time.
7272
session_time: Length of session in seconds.
73-
private: Boolean that indicates whether the job is marked as private. This is only
74-
supported for ``ibm_quantum`` channel. When set to true, input parameters are not
75-
returned, and the results can only be read once. After the results are read or after
76-
a specified time after the job is completed, the results are deleted from the service.
77-
When set to false, the input parameters and results follow the standard retention
78-
behavior.
73+
private: Boolean that indicates whether the job is marked as private. When set to true,
74+
input parameters are not returned, and the results can only be read once.
75+
After the job is completed, input parameters are deleted from the service.
76+
After the results are read, these are also deleted from the service.
77+
When set to false, the input parameters and results follow the
78+
standard retention behavior of the API.
7979
"""
8080
self.backend = backend
8181
self.image = image
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The ``private`` option under :class:`EnvironmentOptions` is now supported on the
2+
``ibm_cloud`` and ``ibm_quantum_platform`` channels (new IBM Quantum Platform). When this option
3+
is set to ``True``, the job will be returned without params and results can only
4+
be retrieved once.
5+
6+
There is also a new :meth:`~.RuntimeJobV2.private` property that returns whether
7+
or not a job is private.

test/integration/test_ibm_job_attributes.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,7 @@ def test_cost_estimation(self):
163163

164164
def test_private_option(self):
165165
"""Test private option."""
166-
if self.dependencies.channel == "ibm_cloud":
167-
raise SkipTest("Cloud channel does not support private jobs")
168-
try:
169-
backend = self.service.backend("test_eagle")
170-
except:
171-
raise SkipTest("test_eagle not available in this environment")
166+
backend = self.dependencies.service.backend(self.dependencies.qpu)
172167

173168
sampler = Sampler(mode=backend)
174169
sampler.options.environment.private = True
@@ -177,3 +172,4 @@ def test_private_option(self):
177172
self.assertFalse(job.inputs)
178173
self.assertTrue(job.result())
179174
self.assertFalse(job.result()) # private job results can only be retrieved once
175+
self.assertTrue(job.private)

0 commit comments

Comments
 (0)