Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/accelerate/src/circuit_library/pauli_evolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use pyo3::{intern, prelude::*};
use qiskit_circuit::circuit_data::CircuitData;
use qiskit_circuit::circuit_instruction::OperationFromPython;
use qiskit_circuit::operations;
use qiskit_circuit::operations::{multiply_param, radd_param, Param, StandardGate};
use qiskit_circuit::operations::{Param, StandardGate};
use qiskit_circuit::packed_instruction::PackedOperation;
use qiskit_circuit::{Clbit, Qubit};
use smallvec::{smallvec, SmallVec};
Expand Down Expand Up @@ -278,7 +278,7 @@ fn multi_qubit_evolution(
// Here we purely have projectors, meaning the target rotation is a phase gate. Remember
// we have to adjust the rotation angle to account for the different conventions;
// RZ(t) = exp(-i t/2 Z) vs. P(t) = diag(1, exp(i t)).
let params: SmallVec<[Param; 3]> = smallvec![multiply_param(&time, -0.5)];
let params: SmallVec<[Param; 3]> = smallvec![time.mul_f64(-0.5)];
let (packed, qubits) = if control_qubits.len() == 1 {
let gate: PackedOperation = StandardGate::Phase.into();
(gate, vec![control_qubits[0]])
Expand Down Expand Up @@ -363,7 +363,7 @@ pub fn py_pauli_evolution(
let time = Param::extract_no_coerce(&tuple.get_item(2)?)?;

if pauli.as_str().chars().all(|p| p == 'i') {
global_phase = radd_param(global_phase, time);
global_phase = global_phase.add(&time);
modified_phase = true;
continue;
}
Expand Down Expand Up @@ -398,7 +398,7 @@ pub fn py_pauli_evolution(
// exp(-i t I). To only use a single multiplication, we apply a factor of -0.5 here.
// This is faster, in particular as long as the parameter expressions are in Python.
if modified_phase {
global_phase = multiply_param(&global_phase, -0.5);
global_phase = global_phase.mul_f64(-0.5);
}

CircuitData::from_packed_operations(num_qubits as u32, 0, evos, global_phase)
Expand Down
14 changes: 6 additions & 8 deletions crates/accelerate/src/circuit_library/pauli_feature_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use pyo3::prelude::*;
use pyo3::types::PySequence;
use pyo3::types::PyString;
use qiskit_circuit::circuit_data::CircuitData;
use qiskit_circuit::operations::{
add_param, multiply_param, multiply_params, Param, StandardGate, StandardInstruction,
};
use qiskit_circuit::operations::{Param, StandardGate, StandardInstruction};
use qiskit_circuit::packed_instruction::PackedOperation;
use qiskit_circuit::{Clbit, Qubit};
use smallvec::{smallvec, SmallVec};
Expand Down Expand Up @@ -178,7 +176,7 @@ fn _get_evolution_layer<'a>(
let evo = pauli_evolution::sparse_term_evolution(
pauli,
indices.into_iter().rev().collect(),
multiply_param(&angle, alpha),
angle.mul_f64(alpha),
true,
false,
);
Expand All @@ -197,13 +195,13 @@ fn _default_reduce(parameters: Vec<Param>) -> Param {
if parameters.len() == 1 {
parameters[0].clone()
} else {
let acc = parameters.iter().fold(Param::Float(1.0), |acc, param| {
multiply_params(acc, add_param(param, -PI))
});
let acc = parameters
.iter()
.fold(Param::Float(1.0), |acc, param| acc.mul(&param.add_f64(-PI)));
if parameters.len() % 2 == 0 {
acc
} else {
multiply_param(&acc, -1.0) // take care of parity
acc.mul_f64(-1.0) // take care of parity
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/circuit/src/circuit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::bit::{
use crate::bit_locator::BitLocator;
use crate::circuit_instruction::{CircuitInstruction, OperationFromPython};
use crate::classical::expr;
use crate::dag_circuit::{add_global_phase, DAGStretchType, DAGVarType};
use crate::dag_circuit::{DAGStretchType, DAGVarType};
use crate::imports::{ANNOTATED_OPERATION, QUANTUM_CIRCUIT};
use crate::interner::{Interned, InternedMap, Interner};
use crate::object_registry::ObjectRegistry;
Expand Down Expand Up @@ -2795,7 +2795,7 @@ impl CircuitData {
Param::Obj(_) => Err(PyTypeError::new_err(
"Invalid parameter type, only float and parameter expression are supported",
)),
_ => self.set_global_phase(add_global_phase(&self.global_phase, value)?),
_ => self.set_global_phase(self.global_phase.add(value)),
}
}

Expand Down
27 changes: 3 additions & 24 deletions crates/circuit/src/dag_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use std::cmp::Ordering;
use std::hash::Hash;
use std::sync::Arc;

use ahash::RandomState;
use approx::relative_eq;
Expand All @@ -36,7 +35,6 @@ use crate::operations::{
ArrayType, Operation, OperationRef, Param, PyInstruction, PythonOperation, StandardGate,
};
use crate::packed_instruction::{PackedInstruction, PackedOperation};
use crate::parameter::parameter_expression::ParameterExpression;
use crate::register_data::RegisterData;
use crate::slice::PySequenceIndex;
use crate::variable_mapper::VariableMapper;
Expand Down Expand Up @@ -6246,7 +6244,7 @@ impl DAGCircuit {

let out_map =
self.substitute_node_with_graph(node_index, other, qubit_map, clbit_map, var_map)?;
self.global_phase = add_global_phase(&self.global_phase, &other.global_phase)?;
self.global_phase = self.global_phase.add(&other.global_phase);

let mut wire_map_dict = HashMap::new();
for (source, target) in clbit_map.iter() {
Expand Down Expand Up @@ -6945,7 +6943,7 @@ impl DAGCircuit {
"Invalid parameter type, only float and parameter expression are supported",
))
}
_ => self.set_global_phase(add_global_phase(&self.global_phase, value)?)?,
_ => self.set_global_phase(self.global_phase.add(value))?,
}
Ok(())
}
Expand Down Expand Up @@ -7407,7 +7405,7 @@ impl DAGCircuit {
}
};

self.global_phase = add_global_phase(&self.global_phase, &other.global_phase)?;
self.global_phase = self.global_phase.add(&other.global_phase);

// This is all the handling we need for realtime variables, if there's no remapping. They:
//
Expand Down Expand Up @@ -8002,25 +8000,6 @@ impl ::std::ops::Index<NodeIndex> for DAGCircuit {
}
}

/// Add to global phase. Global phase can only be Float or ParameterExpression so this
/// does not handle the full possibility of parameter values.
/// TODO replace/merge this with add_param/radd_param
Comment thread
jakelishman marked this conversation as resolved.
pub(crate) fn add_global_phase(phase: &Param, other: &Param) -> PyResult<Param> {
Ok(match [phase, other] {
[Param::Float(a), Param::Float(b)] => Param::Float(a + b),
[Param::Float(a), Param::ParameterExpression(b)] => {
Param::ParameterExpression(Arc::new(b.add(&ParameterExpression::from_f64(*a)).unwrap()))
}
[Param::ParameterExpression(a), Param::Float(b)] => {
Param::ParameterExpression(Arc::new(a.add(&ParameterExpression::from_f64(*b)).unwrap()))
}
[Param::ParameterExpression(a), Param::ParameterExpression(b)] => {
Param::ParameterExpression(Arc::new(a.add(b).expect("Name conflict in add.")))
}
_ => panic!("Invalid global phase"),
})
}

type SortKeyType<'a> = (&'a [Qubit], &'a [Clbit]);

#[cfg(all(test, not(miri)))]
Expand Down
Loading
Loading