qcs_api/apis/
translation_api.rs

1/*
2 * Rigetti QCS API
3 *
4 * # Introduction  This is the documentation for the Rigetti QCS HTTP API.  You can find out more about Rigetti at [https://rigetti.com](https://rigetti.com), and also interact with QCS via the web at [https://qcs.rigetti.com](https://qcs.rigetti.com).  This API is documented in **OpenAPI format** and so is compatible with the dozens of language-specific client generators available [here](https://github.com/OpenAPITools/openapi-generator) and elsewhere on the web.  # Principles  This API follows REST design principles where appropriate, and otherwise an HTTP RPC paradigm. We adhere to the Google [API Improvement Proposals](https://google.aip.dev/general) where reasonable to provide a consistent, intuitive developer experience. HTTP response codes match their specifications, and error messages fit a common format.  # Authentication  All access to the QCS API requires OAuth2 authentication provided by Okta. You can request access [here](https://www.rigetti.com/get-quantum). Once you have a user account, you can download your access token from QCS [here](https://qcs.rigetti.com/auth/token).   That access token is valid for 24 hours after issuance. The value of `access_token` within the JSON file is the token used for authentication (don't use the entire JSON file).  Authenticate requests using the `Authorization` header and a `Bearer` prefix:  ``` curl --header \"Authorization: Bearer eyJraW...Iow\" ```  # Quantum Processor Access  Access to the quantum processors themselves is not yet provided directly by this HTTP API, but is instead performed over ZeroMQ/[rpcq](https://gitlab.com/rigetti/rpcq). Until that changes, we suggest using [pyquil](https://gitlab.com/rigetti/pyquil) to build and execute quantum programs via the Legacy API.  # Legacy API  Our legacy HTTP API remains accessible at https://forest-server.qcs.rigetti.com, and it shares a source of truth with this API's services. You can use either service with the same user account and means of authentication. We strongly recommend using the API documented here, as the legacy API is on the path to deprecation.
5 *
6 * The version of the OpenAPI document: 2020-07-31
7 * Contact: support@rigetti.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12
13use super::{configuration, Error};
14use crate::apis::ResponseContent;
15
16/// struct for typed errors of method [`get_quilt_calibrations`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum GetQuiltCalibrationsError {
20    Status404(crate::models::Error),
21    Status422(crate::models::ValidationError),
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`translate_native_quil_to_encrypted_binary`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum TranslateNativeQuilToEncryptedBinaryError {
29    Status400(crate::models::Error),
30    Status404(crate::models::Error),
31    Status422(crate::models::ValidationError),
32    UnknownValue(serde_json::Value),
33}
34
35/// Retrieve the calibration data used for client-side Quilt generation.
36pub async fn get_quilt_calibrations(
37    configuration: &configuration::Configuration,
38    quantum_processor_id: &str,
39) -> Result<crate::models::GetQuiltCalibrationsResponse, Error<GetQuiltCalibrationsError>> {
40    let local_var_configuration = configuration;
41
42    let local_var_client = &local_var_configuration.client;
43
44    let local_var_uri_str = format!(
45        "{}/v1/quantumProcessors/{quantumProcessorId}/quiltCalibrations",
46        local_var_configuration.base_path,
47        quantumProcessorId = crate::apis::urlencode(quantum_processor_id)
48    );
49    let mut local_var_req_builder =
50        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
51
52    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
53        local_var_req_builder =
54            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
55    }
56    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
57        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
58    };
59
60    let local_var_req = local_var_req_builder.build()?;
61    let local_var_resp = local_var_client.execute(local_var_req).await?;
62
63    let local_var_status = local_var_resp.status();
64    let local_var_content = local_var_resp.text().await?;
65
66    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
67        serde_json::from_str(&local_var_content).map_err(Error::from)
68    } else {
69        let local_var_entity: Option<GetQuiltCalibrationsError> =
70            serde_json::from_str(&local_var_content).ok();
71        let local_var_error = ResponseContent {
72            status: local_var_status,
73            content: local_var_content,
74            entity: local_var_entity,
75        };
76        Err(Error::ResponseError(local_var_error))
77    }
78}
79
80/// Compile Rigetti-native Quil code to encrypted binary form, ready for execution on a Rigetti Quantum Processor.
81pub async fn translate_native_quil_to_encrypted_binary(
82    configuration: &configuration::Configuration,
83    quantum_processor_id: &str,
84    translate_native_quil_to_encrypted_binary_request: crate::models::TranslateNativeQuilToEncryptedBinaryRequest,
85) -> Result<
86    crate::models::TranslateNativeQuilToEncryptedBinaryResponse,
87    Error<TranslateNativeQuilToEncryptedBinaryError>,
88> {
89    let local_var_configuration = configuration;
90
91    let local_var_client = &local_var_configuration.client;
92
93    let local_var_uri_str = format!(
94        "{}/v1/quantumProcessors/{quantumProcessorId}:translateNativeQuilToEncryptedBinary",
95        local_var_configuration.base_path,
96        quantumProcessorId = crate::apis::urlencode(quantum_processor_id)
97    );
98    let mut local_var_req_builder =
99        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
100
101    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
102        local_var_req_builder =
103            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
104    }
105    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
106        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
107    };
108    local_var_req_builder =
109        local_var_req_builder.json(&translate_native_quil_to_encrypted_binary_request);
110
111    let local_var_req = local_var_req_builder.build()?;
112    let local_var_resp = local_var_client.execute(local_var_req).await?;
113
114    let local_var_status = local_var_resp.status();
115    let local_var_content = local_var_resp.text().await?;
116
117    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
118        serde_json::from_str(&local_var_content).map_err(Error::from)
119    } else {
120        let local_var_entity: Option<TranslateNativeQuilToEncryptedBinaryError> =
121            serde_json::from_str(&local_var_content).ok();
122        let local_var_error = ResponseContent {
123            status: local_var_status,
124            content: local_var_content,
125            entity: local_var_entity,
126        };
127        Err(Error::ResponseError(local_var_error))
128    }
129}