1# -*- coding: utf-8 -*- 2# 3# Copyright 2020 The Cirq Developers 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# https://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17 18import google.api_core.grpc_helpers 19 20from cirq_google.engine.client.quantum_v1alpha1.proto import engine_pb2_grpc 21 22 23class QuantumEngineServiceGrpcTransport(object): 24 """gRPC transport class providing stubs for 25 google.cloud.quantum.v1alpha1 QuantumEngineService API. 26 27 The transport provides access to the raw gRPC stubs, 28 which can be used to take advantage of advanced 29 features of gRPC. 30 """ 31 32 # The scopes needed to make gRPC calls to all of the methods defined 33 # in this service. 34 _OAUTH_SCOPES = ('https://www.googleapis.com/auth/cloud-platform',) 35 36 def __init__(self, channel=None, credentials=None, address='quantum.googleapis.com:443'): 37 """Instantiate the transport class. 38 39 Args: 40 channel (grpc.Channel): A ``Channel`` instance through 41 which to make calls. This argument is mutually exclusive 42 with ``credentials``; providing both will raise an exception. 43 credentials (google.auth.credentials.Credentials): The 44 authorization credentials to attach to requests. These 45 credentials identify this application to the service. If none 46 are specified, the client will attempt to ascertain the 47 credentials from the environment. 48 address (str): The address where the service is hosted. 49 """ 50 # If both `channel` and `credentials` are specified, raise an 51 # exception (channels come with credentials baked in already). 52 if channel is not None and credentials is not None: 53 raise ValueError( 54 'The `channel` and `credentials` arguments are mutually exclusive.', 55 ) 56 57 # Create the channel. 58 if channel is None: 59 channel = self.create_channel( 60 address=address, 61 credentials=credentials, 62 options={ 63 'grpc.max_send_message_length': -1, 64 'grpc.max_receive_message_length': -1, 65 }.items(), 66 ) 67 68 self._channel = channel 69 70 # gRPC uses objects called "stubs" that are bound to the 71 # channel and provide a basic method for each RPC. 72 self._stubs = { 73 'quantum_engine_service_stub': engine_pb2_grpc.QuantumEngineServiceStub(channel), 74 } 75 76 @classmethod 77 def create_channel(cls, address='quantum.googleapis.com:443', credentials=None, **kwargs): 78 """Create and return a gRPC channel object. 79 80 Args: 81 address (str): The host for the channel to use. 82 credentials (~.Credentials): The 83 authorization credentials to attach to requests. These 84 credentials identify this application to the service. If 85 none are specified, the client will attempt to ascertain 86 the credentials from the environment. 87 kwargs (dict): Keyword arguments, which are passed to the 88 channel creation. 89 90 Returns: 91 grpc.Channel: A gRPC channel object. 92 """ 93 return google.api_core.grpc_helpers.create_channel( 94 address, credentials=credentials, scopes=cls._OAUTH_SCOPES, **kwargs 95 ) 96 97 @property 98 def channel(self): 99 """The gRPC channel used by the transport. 100 101 Returns: 102 grpc.Channel: A gRPC channel object. 103 """ 104 return self._channel 105 106 @property 107 def create_quantum_program(self): 108 """Return the gRPC stub for 109 :meth:`QuantumEngineServiceClient.create_quantum_program`. 110 111 - 112 113 Returns: 114 Callable: A callable which accepts the appropriate 115 deserialized request object and returns a 116 deserialized response object. 117 """ 118 return self._stubs['quantum_engine_service_stub'].CreateQuantumProgram 119 120 @property 121 def get_quantum_program(self): 122 """Return the gRPC stub for 123 :meth:`QuantumEngineServiceClient.get_quantum_program`. 124 125 - 126 127 Returns: 128 Callable: A callable which accepts the appropriate 129 deserialized request object and returns a 130 deserialized response object. 131 """ 132 return self._stubs['quantum_engine_service_stub'].GetQuantumProgram 133 134 @property 135 def list_quantum_programs(self): 136 """Return the gRPC stub for 137 :meth:`QuantumEngineServiceClient.list_quantum_programs`. 138 139 - 140 141 Returns: 142 Callable: A callable which accepts the appropriate 143 deserialized request object and returns a 144 deserialized response object. 145 """ 146 return self._stubs['quantum_engine_service_stub'].ListQuantumPrograms 147 148 @property 149 def delete_quantum_program(self): 150 """Return the gRPC stub 151 for :meth:`QuantumEngineServiceClient.delete_quantum_program`. 152 153 - 154 155 Returns: 156 Callable: A callable which accepts the appropriate 157 deserialized request object and returns a 158 deserialized response object. 159 """ 160 return self._stubs['quantum_engine_service_stub'].DeleteQuantumProgram 161 162 @property 163 def update_quantum_program(self): 164 """Return the gRPC stub for 165 :meth:`QuantumEngineServiceClient.update_quantum_program`. 166 167 - 168 169 Returns: 170 Callable: A callable which accepts the appropriate 171 deserialized request object and returns a 172 deserialized response object. 173 """ 174 return self._stubs['quantum_engine_service_stub'].UpdateQuantumProgram 175 176 @property 177 def create_quantum_job(self): 178 """Return the gRPC stub for 179 :meth:`QuantumEngineServiceClient.create_quantum_job`. 180 181 - 182 183 Returns: 184 Callable: A callable which accepts the appropriate 185 deserialized request object and returns a 186 deserialized response object. 187 """ 188 return self._stubs['quantum_engine_service_stub'].CreateQuantumJob 189 190 @property 191 def get_quantum_job(self): 192 """Return the gRPC stub for 193 :meth:`QuantumEngineServiceClient.get_quantum_job`. 194 195 - 196 197 Returns: 198 Callable: A callable which accepts the appropriate 199 deserialized request object and returns a 200 deserialized response object. 201 """ 202 return self._stubs['quantum_engine_service_stub'].GetQuantumJob 203 204 @property 205 def list_quantum_jobs(self): 206 """Return the gRPC stub for 207 :meth:`QuantumEngineServiceClient.list_quantum_jobs`. 208 209 - 210 211 Returns: 212 Callable: A callable which accepts the appropriate 213 deserialized request object and returns a 214 deserialized response object. 215 """ 216 return self._stubs['quantum_engine_service_stub'].ListQuantumJobs 217 218 @property 219 def delete_quantum_job(self): 220 """Return the gRPC stub for 221 :meth:`QuantumEngineServiceClient.delete_quantum_job`. 222 223 - 224 225 Returns: 226 Callable: A callable which accepts the appropriate 227 deserialized request object and returns a 228 deserialized response object. 229 """ 230 return self._stubs['quantum_engine_service_stub'].DeleteQuantumJob 231 232 @property 233 def update_quantum_job(self): 234 """Return the gRPC stub for 235 :meth:`QuantumEngineServiceClient.update_quantum_job`. 236 237 - 238 239 Returns: 240 Callable: A callable which accepts the appropriate 241 deserialized request object and returns a 242 deserialized response object. 243 """ 244 return self._stubs['quantum_engine_service_stub'].UpdateQuantumJob 245 246 @property 247 def cancel_quantum_job(self): 248 """Return the gRPC stub for 249 :meth:`QuantumEngineServiceClient.cancel_quantum_job`. 250 251 - 252 253 Returns: 254 Callable: A callable which accepts the appropriate 255 deserialized request object and returns a 256 deserialized response object. 257 """ 258 return self._stubs['quantum_engine_service_stub'].CancelQuantumJob 259 260 @property 261 def list_quantum_job_events(self): 262 """Return the gRPC stub for 263 :meth:`QuantumEngineServiceClient.list_quantum_job_events`. 264 265 - 266 267 Returns: 268 Callable: A callable which accepts the appropriate 269 deserialized request object and returns a 270 deserialized response object. 271 """ 272 return self._stubs['quantum_engine_service_stub'].ListQuantumJobEvents 273 274 @property 275 def get_quantum_result(self): 276 """Return the gRPC stub for 277 :meth:`QuantumEngineServiceClient.get_quantum_result`. 278 279 - 280 281 Returns: 282 Callable: A callable which accepts the appropriate 283 deserialized request object and returns a 284 deserialized response object. 285 """ 286 return self._stubs['quantum_engine_service_stub'].GetQuantumResult 287 288 @property 289 def list_quantum_processors(self): 290 """Return the gRPC stub for 291 :meth:`QuantumEngineServiceClient.list_quantum_processors`. 292 293 - 294 295 Returns: 296 Callable: A callable which accepts the appropriate 297 deserialized request object and returns a 298 deserialized response object. 299 """ 300 return self._stubs['quantum_engine_service_stub'].ListQuantumProcessors 301 302 @property 303 def get_quantum_processor(self): 304 """Return the gRPC stub for 305 :meth:`QuantumEngineServiceClient.get_quantum_processor`. 306 307 - 308 309 Returns: 310 Callable: A callable which accepts the appropriate 311 deserialized request object and returns a 312 deserialized response object. 313 """ 314 return self._stubs['quantum_engine_service_stub'].GetQuantumProcessor 315 316 @property 317 def list_quantum_calibrations(self): 318 """Return the gRPC stub for 319 :meth:`QuantumEngineServiceClient.list_quantum_calibrations`. 320 321 - 322 323 Returns: 324 Callable: A callable which accepts the appropriate 325 deserialized request object and returns a 326 deserialized response object. 327 """ 328 return self._stubs['quantum_engine_service_stub'].ListQuantumCalibrations 329 330 @property 331 def get_quantum_calibration(self): 332 """Return the gRPC stub for 333 :meth:`QuantumEngineServiceClient.get_quantum_calibration`. 334 335 - 336 337 Returns: 338 Callable: A callable which accepts the appropriate 339 deserialized request object and returns a 340 deserialized response object. 341 """ 342 return self._stubs['quantum_engine_service_stub'].GetQuantumCalibration 343 344 @property 345 def create_quantum_reservation(self): 346 """Return the gRPC stub for 347 :meth:`QuantumEngineServiceClient.create_quantum_reservation`. 348 349 - 350 351 Returns: 352 Callable: A callable which accepts the appropriate 353 deserialized request object and returns a 354 deserialized response object. 355 """ 356 return self._stubs['quantum_engine_service_stub'].CreateQuantumReservation 357 358 @property 359 def cancel_quantum_reservation(self): 360 """Return the gRPC stub for 361 :meth:`QuantumEngineServiceClient.cancel_quantum_reservation`. 362 363 - 364 365 Returns: 366 Callable: A callable which accepts the appropriate 367 deserialized request object and returns a 368 deserialized response object. 369 """ 370 return self._stubs['quantum_engine_service_stub'].CancelQuantumReservation 371 372 @property 373 def delete_quantum_reservation(self): 374 """Return the gRPC stub for 375 :meth:`QuantumEngineServiceClient.delete_quantum_reservation`. 376 377 - 378 379 Returns: 380 Callable: A callable which accepts the appropriate 381 deserialized request object and returns a 382 deserialized response object. 383 """ 384 return self._stubs['quantum_engine_service_stub'].DeleteQuantumReservation 385 386 @property 387 def get_quantum_reservation(self): 388 """Return the gRPC stub for 389 :meth:`QuantumEngineServiceClient.get_quantum_reservation`. 390 391 - 392 393 Returns: 394 Callable: A callable which accepts the appropriate 395 deserialized request object and returns a 396 deserialized response object. 397 """ 398 return self._stubs['quantum_engine_service_stub'].GetQuantumReservation 399 400 @property 401 def list_quantum_reservations(self): 402 """Return the gRPC stub for 403 :meth:`QuantumEngineServiceClient.list_quantum_reservations`. 404 405 - 406 407 Returns: 408 Callable: A callable which accepts the appropriate 409 deserialized request object and returns a 410 deserialized response object. 411 """ 412 return self._stubs['quantum_engine_service_stub'].ListQuantumReservations 413 414 @property 415 def update_quantum_reservation(self): 416 """Return the gRPC stub for 417 :meth:`QuantumEngineServiceClient.update_quantum_reservation`. 418 419 - 420 421 Returns: 422 Callable: A callable which accepts the appropriate 423 deserialized request object and returns a 424 deserialized response object. 425 """ 426 return self._stubs['quantum_engine_service_stub'].UpdateQuantumReservation 427 428 @property 429 def quantum_run_stream(self): 430 """Return the gRPC stub for 431 :meth:`QuantumEngineServiceClient.quantum_run_stream`. 432 433 - 434 435 Returns: 436 Callable: A callable which accepts the appropriate 437 deserialized request object and returns a 438 deserialized response object. 439 """ 440 return self._stubs['quantum_engine_service_stub'].QuantumRunStream 441 442 @property 443 def list_quantum_reservation_grants(self): 444 """Return the gRPC stub for 445 :meth:`QuantumEngineServiceClient.list_quantum_reservation_grants`. 446 447 - 448 449 Returns: 450 Callable: A callable which accepts the appropriate 451 deserialized request object and returns a 452 deserialized response object. 453 """ 454 return self._stubs['quantum_engine_service_stub'].ListQuantumReservationGrants 455 456 @property 457 def reallocate_quantum_reservation_grant(self): 458 """Return the gRPC stub for 459 :meth:`QuantumEngineServiceClient.reallocate_quantum_reservation_grant`. 460 461 - 462 463 Returns: 464 Callable: A callable which accepts the appropriate 465 deserialized request object and returns a 466 deserialized response object. 467 """ 468 return self._stubs['quantum_engine_service_stub'].ReallocateQuantumReservationGrant 469 470 @property 471 def list_quantum_reservation_budgets(self): 472 """Return the gRPC stub for 473 :meth:`QuantumEngineServiceClient.list_quantum_reservation_budgets`. 474 475 - 476 477 Returns: 478 Callable: A callable which accepts the appropriate 479 deserialized request object and returns a 480 deserialized response object. 481 """ 482 return self._stubs['quantum_engine_service_stub'].ListQuantumReservationBudgets 483 484 @property 485 def list_quantum_time_slots(self): 486 """Return the gRPC stub for 487 :meth:`QuantumEngineServiceClient.list_quantum_time_slots`. 488 489 - 490 491 Returns: 492 Callable: A callable which accepts the appropriate 493 deserialized request object and returns a 494 deserialized response object. 495 """ 496 return self._stubs['quantum_engine_service_stub'].ListQuantumTimeSlots 497