qcs_api_client_grpc/gen/
services.translation.rs

1// Copyright 2023 Rigetti Computing
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15
16// This file is @generated by prost-build.
17/// Options specified on RPCs that translate Quil to a ControllerJob. Intended to support custom pre-processing
18/// and other translation features.
19#[derive(Clone, Copy, PartialEq, ::prost::Message)]
20pub struct TranslationOptions {
21    /// When set, the client program will be pre-processed via the Q-CTRL API
22    /// before translation.
23    #[prost(message, optional, tag = "1")]
24    pub q_ctrl: ::core::option::Option<translation_options::QCtrl>,
25    /// The backend to use for translation, to include relevant options.
26    /// If neither is specified, the implementing service may select the
27    /// translation backend and options.
28    #[prost(oneof = "translation_options::TranslationBackend", tags = "101, 102")]
29    pub translation_backend: ::core::option::Option<
30        translation_options::TranslationBackend,
31    >,
32}
33/// Nested message and enum types in `TranslationOptions`.
34pub mod translation_options {
35    #[derive(Clone, Copy, PartialEq, ::prost::Message)]
36    pub struct QCtrl {
37        /// Indicates whether Q-CTRL pre-processing should consider the set of
38        /// program qubits to be fixed. If true, Q-CTRL may only remap qubits to
39        /// others specified within the user-submitted program. If false, Q-CTRL may
40        /// remap program qubits to any physical qubit on the device in order to
41        /// optimize the program.
42        ///
43        /// Note, this attribute is used to set `fixed_layouts` attribute on Q-CTRL's
44        /// `CompileOptions` message. Q-CTRL supports compilation of mutliple programs
45        /// at once, while Rigetti's `TranslationOptions` are currently scoped to a
46        /// single program. As such, we use `fixed_layout` rather than `fixed_layouts`.
47        #[prost(bool, optional, tag = "1")]
48        pub fixed_layout: ::core::option::Option<bool>,
49    }
50    /// The backend to use for translation, to include relevant options.
51    /// If neither is specified, the implementing service may select the
52    /// translation backend and options.
53    #[derive(Clone, Copy, PartialEq, ::prost::Oneof)]
54    pub enum TranslationBackend {
55        #[prost(message, tag = "101")]
56        V1(super::BackendV1Options),
57        #[prost(message, tag = "102")]
58        V2(super::BackendV2Options),
59    }
60}
61/// Options for translation backend V1
62#[derive(Clone, Copy, PartialEq, ::prost::Message)]
63pub struct BackendV1Options {}
64/// Options for translation backend V2
65#[derive(Clone, Copy, PartialEq, ::prost::Message)]
66pub struct BackendV2Options {
67    /// Whether to prepend the default calibrations for a particular QPU to the program.
68    /// This may be set to false if you have prepended your own calibrations, or are submitting
69    /// a pre-calibrated pulse-level program which does not need further expansion.
70    #[prost(bool, optional, tag = "1")]
71    pub prepend_default_calibrations: ::core::option::Option<bool>,
72    /// The number of seconds to stall at the beginning of each num-shots loop iteration in order to allow adiabatic reset.
73    #[prost(double, optional, tag = "2")]
74    pub passive_reset_delay_seconds: ::core::option::Option<f64>,
75    /// Whether to disable bounds checks on dynamic memory access. Only available to authorized users.
76    #[prost(bool, optional, tag = "4")]
77    pub allow_unchecked_pointer_arithmetic: ::core::option::Option<bool>,
78    /// Whether to skip program frame validation against Rigetti calibrations.
79    #[prost(bool, optional, tag = "5")]
80    pub allow_frame_redefinition: ::core::option::Option<bool>,
81    /// Whether to force all real-time-classified readout values to be stored in sequencer memory. If false or unset, only readout values that are
82    /// read by the program are written to sequencer memory following readout.
83    #[prost(bool, optional, tag = "6")]
84    pub store_all_readout_values: ::core::option::Option<bool>,
85}
86#[derive(Clone, PartialEq, ::prost::Message)]
87pub struct TranslateQuilToEncryptedControllerJobRequest {
88    #[prost(string, tag = "1")]
89    pub quantum_processor_id: ::prost::alloc::string::String,
90    #[prost(string, tag = "2")]
91    pub quil_program: ::prost::alloc::string::String,
92    /// Specification of optional translation features.
93    #[prost(message, optional, tag = "4")]
94    pub options: ::core::option::Option<TranslationOptions>,
95    #[prost(
96        oneof = "translate_quil_to_encrypted_controller_job_request::NumShots",
97        tags = "3"
98    )]
99    pub num_shots: ::core::option::Option<
100        translate_quil_to_encrypted_controller_job_request::NumShots,
101    >,
102}
103/// Nested message and enum types in `TranslateQuilToEncryptedControllerJobRequest`.
104pub mod translate_quil_to_encrypted_controller_job_request {
105    #[derive(Clone, Copy, PartialEq, ::prost::Oneof)]
106    pub enum NumShots {
107        #[prost(uint32, tag = "3")]
108        NumShotsValue(u32),
109    }
110}
111#[derive(Clone, PartialEq, ::prost::Message)]
112pub struct TranslateQuilToEncryptedControllerJobResponse {
113    #[prost(message, optional, tag = "1")]
114    pub job: ::core::option::Option<
115        super::super::models::controller::EncryptedControllerJob,
116    >,
117    #[prost(message, optional, tag = "2")]
118    pub metadata: ::core::option::Option<
119        super::super::models::translation::QuilTranslationMetadata,
120    >,
121}
122#[derive(Clone, PartialEq, ::prost::Message)]
123pub struct QuantumProcessorQuilCalibrationProgram {
124    /// The Quil program containing the requested calibrations
125    #[prost(string, tag = "1")]
126    pub quil_calibration_program: ::prost::alloc::string::String,
127}
128#[derive(Clone, PartialEq, ::prost::Message)]
129pub struct GetQuantumProcessorQuilCalibrationProgramRequest {
130    /// The quantum processor for which to retrieve the calibration program.
131    #[prost(string, tag = "1")]
132    pub quantum_processor_id: ::prost::alloc::string::String,
133}
134/// Generated client implementations.
135pub mod translation_client {
136    #![allow(
137        unused_variables,
138        dead_code,
139        missing_docs,
140        clippy::wildcard_imports,
141        clippy::let_unit_value,
142    )]
143    use tonic::codegen::*;
144    use tonic::codegen::http::Uri;
145    #[derive(Debug, Clone)]
146    pub struct TranslationClient<T> {
147        inner: tonic::client::Grpc<T>,
148    }
149    impl TranslationClient<tonic::transport::Channel> {
150        /// Attempt to create a new client by connecting to a given endpoint.
151        pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
152        where
153            D: TryInto<tonic::transport::Endpoint>,
154            D::Error: Into<StdError>,
155        {
156            let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
157            Ok(Self::new(conn))
158        }
159    }
160    impl<T> TranslationClient<T>
161    where
162        T: tonic::client::GrpcService<tonic::body::BoxBody>,
163        T::Error: Into<StdError>,
164        T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
165        <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
166    {
167        pub fn new(inner: T) -> Self {
168            let inner = tonic::client::Grpc::new(inner);
169            Self { inner }
170        }
171        pub fn with_origin(inner: T, origin: Uri) -> Self {
172            let inner = tonic::client::Grpc::with_origin(inner, origin);
173            Self { inner }
174        }
175        pub fn with_interceptor<F>(
176            inner: T,
177            interceptor: F,
178        ) -> TranslationClient<InterceptedService<T, F>>
179        where
180            F: tonic::service::Interceptor,
181            T::ResponseBody: Default,
182            T: tonic::codegen::Service<
183                http::Request<tonic::body::BoxBody>,
184                Response = http::Response<
185                    <T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
186                >,
187            >,
188            <T as tonic::codegen::Service<
189                http::Request<tonic::body::BoxBody>,
190            >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
191        {
192            TranslationClient::new(InterceptedService::new(inner, interceptor))
193        }
194        /// Compress requests with the given encoding.
195        ///
196        /// This requires the server to support it otherwise it might respond with an
197        /// error.
198        #[must_use]
199        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
200            self.inner = self.inner.send_compressed(encoding);
201            self
202        }
203        /// Enable decompressing responses.
204        #[must_use]
205        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
206            self.inner = self.inner.accept_compressed(encoding);
207            self
208        }
209        /// Limits the maximum size of a decoded message.
210        ///
211        /// Default: `4MB`
212        #[must_use]
213        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
214            self.inner = self.inner.max_decoding_message_size(limit);
215            self
216        }
217        /// Limits the maximum size of an encoded message.
218        ///
219        /// Default: `usize::MAX`
220        #[must_use]
221        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
222            self.inner = self.inner.max_encoding_message_size(limit);
223            self
224        }
225        pub async fn translate_quil_to_encrypted_controller_job(
226            &mut self,
227            request: impl tonic::IntoRequest<
228                super::TranslateQuilToEncryptedControllerJobRequest,
229            >,
230        ) -> std::result::Result<
231            tonic::Response<super::TranslateQuilToEncryptedControllerJobResponse>,
232            tonic::Status,
233        > {
234            self.inner
235                .ready()
236                .await
237                .map_err(|e| {
238                    tonic::Status::unknown(
239                        format!("Service was not ready: {}", e.into()),
240                    )
241                })?;
242            let codec = tonic::codec::ProstCodec::default();
243            let path = http::uri::PathAndQuery::from_static(
244                "/services.translation.Translation/TranslateQuilToEncryptedControllerJob",
245            );
246            let mut req = request.into_request();
247            req.extensions_mut()
248                .insert(
249                    GrpcMethod::new(
250                        "services.translation.Translation",
251                        "TranslateQuilToEncryptedControllerJob",
252                    ),
253                );
254            self.inner.unary(req, path, codec).await
255        }
256        /// Get the current calibration program for the given quantum processor.
257        pub async fn get_quantum_processor_quil_calibration_program(
258            &mut self,
259            request: impl tonic::IntoRequest<
260                super::GetQuantumProcessorQuilCalibrationProgramRequest,
261            >,
262        ) -> std::result::Result<
263            tonic::Response<super::QuantumProcessorQuilCalibrationProgram>,
264            tonic::Status,
265        > {
266            self.inner
267                .ready()
268                .await
269                .map_err(|e| {
270                    tonic::Status::unknown(
271                        format!("Service was not ready: {}", e.into()),
272                    )
273                })?;
274            let codec = tonic::codec::ProstCodec::default();
275            let path = http::uri::PathAndQuery::from_static(
276                "/services.translation.Translation/GetQuantumProcessorQuilCalibrationProgram",
277            );
278            let mut req = request.into_request();
279            req.extensions_mut()
280                .insert(
281                    GrpcMethod::new(
282                        "services.translation.Translation",
283                        "GetQuantumProcessorQuilCalibrationProgram",
284                    ),
285                );
286            self.inner.unary(req, path, codec).await
287        }
288    }
289}
290/// Generated server implementations.
291#[cfg(feature = "server")]
292pub mod translation_server {
293    #![allow(
294        unused_variables,
295        dead_code,
296        missing_docs,
297        clippy::wildcard_imports,
298        clippy::let_unit_value,
299    )]
300    use tonic::codegen::*;
301    /// Generated trait containing gRPC methods that should be implemented for use with TranslationServer.
302    #[async_trait]
303    pub trait Translation: std::marker::Send + std::marker::Sync + 'static {
304        async fn translate_quil_to_encrypted_controller_job(
305            &self,
306            request: tonic::Request<super::TranslateQuilToEncryptedControllerJobRequest>,
307        ) -> std::result::Result<
308            tonic::Response<super::TranslateQuilToEncryptedControllerJobResponse>,
309            tonic::Status,
310        >;
311        /// Get the current calibration program for the given quantum processor.
312        async fn get_quantum_processor_quil_calibration_program(
313            &self,
314            request: tonic::Request<
315                super::GetQuantumProcessorQuilCalibrationProgramRequest,
316            >,
317        ) -> std::result::Result<
318            tonic::Response<super::QuantumProcessorQuilCalibrationProgram>,
319            tonic::Status,
320        >;
321    }
322    #[derive(Debug)]
323    pub struct TranslationServer<T> {
324        inner: Arc<T>,
325        accept_compression_encodings: EnabledCompressionEncodings,
326        send_compression_encodings: EnabledCompressionEncodings,
327        max_decoding_message_size: Option<usize>,
328        max_encoding_message_size: Option<usize>,
329    }
330    impl<T> TranslationServer<T> {
331        pub fn new(inner: T) -> Self {
332            Self::from_arc(Arc::new(inner))
333        }
334        pub fn from_arc(inner: Arc<T>) -> Self {
335            Self {
336                inner,
337                accept_compression_encodings: Default::default(),
338                send_compression_encodings: Default::default(),
339                max_decoding_message_size: None,
340                max_encoding_message_size: None,
341            }
342        }
343        pub fn with_interceptor<F>(
344            inner: T,
345            interceptor: F,
346        ) -> InterceptedService<Self, F>
347        where
348            F: tonic::service::Interceptor,
349        {
350            InterceptedService::new(Self::new(inner), interceptor)
351        }
352        /// Enable decompressing requests with the given encoding.
353        #[must_use]
354        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
355            self.accept_compression_encodings.enable(encoding);
356            self
357        }
358        /// Compress responses with the given encoding, if the client supports it.
359        #[must_use]
360        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
361            self.send_compression_encodings.enable(encoding);
362            self
363        }
364        /// Limits the maximum size of a decoded message.
365        ///
366        /// Default: `4MB`
367        #[must_use]
368        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
369            self.max_decoding_message_size = Some(limit);
370            self
371        }
372        /// Limits the maximum size of an encoded message.
373        ///
374        /// Default: `usize::MAX`
375        #[must_use]
376        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
377            self.max_encoding_message_size = Some(limit);
378            self
379        }
380    }
381    impl<T, B> tonic::codegen::Service<http::Request<B>> for TranslationServer<T>
382    where
383        T: Translation,
384        B: Body + std::marker::Send + 'static,
385        B::Error: Into<StdError> + std::marker::Send + 'static,
386    {
387        type Response = http::Response<tonic::body::BoxBody>;
388        type Error = std::convert::Infallible;
389        type Future = BoxFuture<Self::Response, Self::Error>;
390        fn poll_ready(
391            &mut self,
392            _cx: &mut Context<'_>,
393        ) -> Poll<std::result::Result<(), Self::Error>> {
394            Poll::Ready(Ok(()))
395        }
396        fn call(&mut self, req: http::Request<B>) -> Self::Future {
397            match req.uri().path() {
398                "/services.translation.Translation/TranslateQuilToEncryptedControllerJob" => {
399                    #[allow(non_camel_case_types)]
400                    struct TranslateQuilToEncryptedControllerJobSvc<T: Translation>(
401                        pub Arc<T>,
402                    );
403                    impl<
404                        T: Translation,
405                    > tonic::server::UnaryService<
406                        super::TranslateQuilToEncryptedControllerJobRequest,
407                    > for TranslateQuilToEncryptedControllerJobSvc<T> {
408                        type Response = super::TranslateQuilToEncryptedControllerJobResponse;
409                        type Future = BoxFuture<
410                            tonic::Response<Self::Response>,
411                            tonic::Status,
412                        >;
413                        fn call(
414                            &mut self,
415                            request: tonic::Request<
416                                super::TranslateQuilToEncryptedControllerJobRequest,
417                            >,
418                        ) -> Self::Future {
419                            let inner = Arc::clone(&self.0);
420                            let fut = async move {
421                                <T as Translation>::translate_quil_to_encrypted_controller_job(
422                                        &inner,
423                                        request,
424                                    )
425                                    .await
426                            };
427                            Box::pin(fut)
428                        }
429                    }
430                    let accept_compression_encodings = self.accept_compression_encodings;
431                    let send_compression_encodings = self.send_compression_encodings;
432                    let max_decoding_message_size = self.max_decoding_message_size;
433                    let max_encoding_message_size = self.max_encoding_message_size;
434                    let inner = self.inner.clone();
435                    let fut = async move {
436                        let method = TranslateQuilToEncryptedControllerJobSvc(inner);
437                        let codec = tonic::codec::ProstCodec::default();
438                        let mut grpc = tonic::server::Grpc::new(codec)
439                            .apply_compression_config(
440                                accept_compression_encodings,
441                                send_compression_encodings,
442                            )
443                            .apply_max_message_size_config(
444                                max_decoding_message_size,
445                                max_encoding_message_size,
446                            );
447                        let res = grpc.unary(method, req).await;
448                        Ok(res)
449                    };
450                    Box::pin(fut)
451                }
452                "/services.translation.Translation/GetQuantumProcessorQuilCalibrationProgram" => {
453                    #[allow(non_camel_case_types)]
454                    struct GetQuantumProcessorQuilCalibrationProgramSvc<T: Translation>(
455                        pub Arc<T>,
456                    );
457                    impl<
458                        T: Translation,
459                    > tonic::server::UnaryService<
460                        super::GetQuantumProcessorQuilCalibrationProgramRequest,
461                    > for GetQuantumProcessorQuilCalibrationProgramSvc<T> {
462                        type Response = super::QuantumProcessorQuilCalibrationProgram;
463                        type Future = BoxFuture<
464                            tonic::Response<Self::Response>,
465                            tonic::Status,
466                        >;
467                        fn call(
468                            &mut self,
469                            request: tonic::Request<
470                                super::GetQuantumProcessorQuilCalibrationProgramRequest,
471                            >,
472                        ) -> Self::Future {
473                            let inner = Arc::clone(&self.0);
474                            let fut = async move {
475                                <T as Translation>::get_quantum_processor_quil_calibration_program(
476                                        &inner,
477                                        request,
478                                    )
479                                    .await
480                            };
481                            Box::pin(fut)
482                        }
483                    }
484                    let accept_compression_encodings = self.accept_compression_encodings;
485                    let send_compression_encodings = self.send_compression_encodings;
486                    let max_decoding_message_size = self.max_decoding_message_size;
487                    let max_encoding_message_size = self.max_encoding_message_size;
488                    let inner = self.inner.clone();
489                    let fut = async move {
490                        let method = GetQuantumProcessorQuilCalibrationProgramSvc(inner);
491                        let codec = tonic::codec::ProstCodec::default();
492                        let mut grpc = tonic::server::Grpc::new(codec)
493                            .apply_compression_config(
494                                accept_compression_encodings,
495                                send_compression_encodings,
496                            )
497                            .apply_max_message_size_config(
498                                max_decoding_message_size,
499                                max_encoding_message_size,
500                            );
501                        let res = grpc.unary(method, req).await;
502                        Ok(res)
503                    };
504                    Box::pin(fut)
505                }
506                _ => {
507                    Box::pin(async move {
508                        let mut response = http::Response::new(empty_body());
509                        let headers = response.headers_mut();
510                        headers
511                            .insert(
512                                tonic::Status::GRPC_STATUS,
513                                (tonic::Code::Unimplemented as i32).into(),
514                            );
515                        headers
516                            .insert(
517                                http::header::CONTENT_TYPE,
518                                tonic::metadata::GRPC_CONTENT_TYPE,
519                            );
520                        Ok(response)
521                    })
522                }
523            }
524        }
525    }
526    impl<T> Clone for TranslationServer<T> {
527        fn clone(&self) -> Self {
528            let inner = self.inner.clone();
529            Self {
530                inner,
531                accept_compression_encodings: self.accept_compression_encodings,
532                send_compression_encodings: self.send_compression_encodings,
533                max_decoding_message_size: self.max_decoding_message_size,
534                max_encoding_message_size: self.max_encoding_message_size,
535            }
536        }
537    }
538    /// Generated gRPC service name
539    pub const SERVICE_NAME: &str = "services.translation.Translation";
540    impl<T> tonic::server::NamedService for TranslationServer<T> {
541        const NAME: &'static str = SERVICE_NAME;
542    }
543}
544