Skip to content

Commit

Permalink
feat!: remove all code related to arithmetic rewriting (#480)
Browse files Browse the repository at this point in the history
* feat!: remove all code related to arithmetic rewriting

* chore: remove remaining rewrite_arithmetic stubs
  • Loading branch information
kalzoo authored Jun 25, 2024
1 parent 400b9a6 commit 223c276
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 869 deletions.
6 changes: 0 additions & 6 deletions crates/lib/src/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::client::Qcs;
use crate::compiler::quilc::{self, CompilerOpts};
use crate::execution_data::{self, ResultData};
use crate::qpu::api::{ExecutionOptions, JobId};
use crate::qpu::rewrite_arithmetic;
use crate::qpu::translation::TranslationOptions;
use crate::qpu::ExecutionError;
use crate::qvm::http::AddressRequest;
Expand Down Expand Up @@ -658,9 +657,6 @@ pub enum Error {
/// There was a problem when translating the Quil program.
#[error("There was a problem translating the Quil program: {0}")]
Translation(String),
/// There was a problem when rewriting parameter arithmetic in the Quil program.
#[error("There was a problem rewriting parameter arithmetic in the Quil program: {0}")]
RewriteArithmetic(#[from] rewrite_arithmetic::Error),
/// There was a problem when substituting parameters in the Quil program.
#[error("There was a problem substituting parameters in the Quil program: {0}")]
Substitution(String),
Expand Down Expand Up @@ -721,9 +717,7 @@ impl From<ExecutionError> for Error {
ExecutionError::Quil(e) => Self::Quil(e),
ExecutionError::ToQuil(e) => Self::ToQuil(e),
ExecutionError::Compilation { details } => Self::Compilation(details),
ExecutionError::RewriteArithmetic(e) => Self::RewriteArithmetic(e),
ExecutionError::RpcqClient(e) => Self::Unexpected(format!("{e:?}")),
ExecutionError::Substitution(message) => Self::Substitution(message),
ExecutionError::QpuApi(e) => Self::QpuApiError(e),
}
}
Expand Down
59 changes: 8 additions & 51 deletions crates/lib/src/qpu/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ use std::sync::Arc;
use std::time::Duration;

use quil_rs::program::ProgramError;
use quil_rs::quil::ToQuilError;
use quil_rs::quil::{Quil, ToQuilError};

use quil_rs::Program;
#[cfg(feature = "tracing")]
use tracing::trace;

use crate::compiler::rpcq;
use crate::executable::Parameters;
use crate::execution_data::{MemoryReferenceParseError, ResultData};
use crate::qpu::{rewrite_arithmetic, translation::translate};
use crate::qpu::translation::translate;
use crate::{ExecutionData, JobHandle};

use super::api::{
retrieve_results, submit, ConnectionStrategy, ExecutionOptions, ExecutionOptionsBuilder,
};
use super::rewrite_arithmetic::RewrittenProgram;
use super::translation::{EncryptedTranslationResult, TranslationOptions};
use super::QpuResultData;
use super::{get_isa, GetIsaError};
Expand All @@ -33,7 +33,7 @@ use crate::compiler::quilc::{self, CompilerOpts, TargetDevice};
/// same number of shots.
#[derive(Debug, Clone)]
pub(crate) struct Execution<'a> {
program: RewrittenProgram,
program: Program,
pub(crate) quantum_processor_id: Cow<'a, str>,
pub(crate) shots: NonZeroU16,
client: Arc<Qcs>,
Expand All @@ -59,12 +59,8 @@ pub(crate) enum Error {
ReadoutParse(#[from] MemoryReferenceParseError),
#[error("Problem when compiling program: {details}")]
Compilation { details: String },
#[error("Program when translating the program: {0}")]
RewriteArithmetic(#[from] rewrite_arithmetic::Error),
#[error("Problem when getting RPCQ client: {0}")]
RpcqClient(#[from] rpcq::Error),
#[error("Program when getting substitutions for program: {0}")]
Substitution(String),
#[error("Problem making a request to the QPU: {0}")]
QpuApi(#[from] super::api::QpuApiError),
}
Expand Down Expand Up @@ -155,13 +151,11 @@ impl<'a> Execution<'a> {
quil.parse().map_err(Error::Quil)?
};

let rewritten = RewrittenProgram::try_from(program).map_err(Error::RewriteArithmetic)?;

Ok(Self {
program: rewritten,
program,
quantum_processor_id,
client,
shots,
client,
})
}

Expand All @@ -172,7 +166,7 @@ impl<'a> Execution<'a> {
) -> Result<EncryptedTranslationResult, Error> {
let encrpyted_translation_result = translate(
self.quantum_processor_id.as_ref(),
&self.program.to_string()?.0,
&self.program.to_quil()?,
self.shots.get().into(),
self.client.as_ref(),
options,
Expand Down Expand Up @@ -234,14 +228,10 @@ impl<'a> Execution<'a> {
let EncryptedTranslationResult { job, readout_map } =
self.translate(translation_options).await?;

let patch_values = self
.get_substitutions(params)
.map_err(Error::Substitution)?;

let job_id = submit(
quantum_processor_id,
job,
&patch_values,
params,
self.client.as_ref(),
execution_options,
)
Expand Down Expand Up @@ -303,37 +293,4 @@ impl<'a> Execution<'a> {
)),
})
}

/// Take the user-provided map of [`Parameters`] and produce the map of substitutions which
/// should be given to QCS with the executable.
///
/// # Example
///
/// If there was a Quil program:
///
/// ```quil
/// DECLARE theta REAL
///
/// RX(theta) 0
/// RX(theta + 1) 0
/// RX(theta + 2) 0
/// ```
///
/// It would be converted (in [`Execution::new`]) to something like:
///
/// ```quil
/// DECLARE __SUBST REAL[2]
/// DECLARE theta REAL[1]
///
/// RX(theta) 0
/// RX(__SUBST[0]) 0
/// RX(__SUBST[1]) 0
/// ```
///
/// Because QPUs do not evaluate expressions themselves. This function creates the values for
/// `__SUBST` by calculating the original expressions given the user-provided params (in this
/// case just `theta`).
fn get_substitutions(&self, params: &Parameters) -> Result<Parameters, String> {
rewrite_arithmetic::get_substitutions(&self.program.substitutions, params)
}
}
1 change: 0 additions & 1 deletion crates/lib/src/qpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use tokio::time::error::Elapsed;
pub mod api;
mod execution;
pub mod result_data;
pub mod rewrite_arithmetic;
pub mod translation;

pub(crate) use execution::{Error as ExecutionError, Execution};
Expand Down
Loading

0 comments on commit 223c276

Please sign in to comment.