use super::commutation::OperationView;
use crate::circuit::{Instruction, ParameterValue, ValueInstruction, ValueOperation};
use crate::compile::CompilerError;
use crate::compile::transform::decompose::unitary::{
TargetAwareSynthesisCost, TwoQubitSynthesisTarget, TwoQubitUnitaryDecomposeBasis,
target_aware_cost_of_value_operations,
};
pub(crate) type ResynthesisCost = TargetAwareSynthesisCost;
pub(crate) fn cost_of_source_value_operations(
operations: &[ValueOperation],
target: &TwoQubitSynthesisTarget,
) -> Result<ResynthesisCost, CompilerError> {
let mut cost = target_aware_cost_of_value_operations(
operations,
target,
TwoQubitUnitaryDecomposeBasis::PauliRotations,
)?;
cost.backend_order = 0;
Ok(cost)
}
pub(crate) fn value_operations_of_source_ops(
ops: &[&OperationView<'_>],
) -> Result<Vec<ValueOperation>, CompilerError> {
ops.iter()
.map(|view| {
let Instruction::Standard(gate) = view.operation.instruction else {
return Err(CompilerError::InvariantViolation(
"resynthesis cost requested for non-standard operation".to_string(),
));
};
let params = view
.params
.iter()
.map(|parameter| parameter.evaluate(&None))
.collect::<Result<Vec<_>, _>>()
.map_err(|_| {
CompilerError::InvariantViolation(
"resynthesis cost requested for symbolic operation".to_string(),
)
})?;
Ok(ValueOperation {
instruction: ValueInstruction::from_instruction(Instruction::Standard(gate)),
qubits: view.operation.qubits.clone(),
params: params.into_iter().map(ParameterValue::Fixed).collect(),
label: view.operation.label.clone(),
})
})
.collect()
}
#[cfg(test)]
#[path = "cost_test.rs"]
mod cost_test;