Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
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::{DAGStretchType, DAGVarType, add_global_phase};
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 @@ -3054,7 +3054,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.try_add_scalar(value)?),
}
}

Expand Down
33 changes: 3 additions & 30 deletions crates/circuit/src/dag_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6898,7 +6898,7 @@ impl DAGCircuit {
let out_map = self.substitute_node_with_graph(
node_index, other, qubit_map, clbit_map, var_map, block_map,
)?;
self.global_phase = add_global_phase(&self.global_phase, &other.global_phase)?;
self.global_phase = self.global_phase.try_add_scalar(&other.global_phase)?;

let mut wire_map_dict = HashMap::new();
for (source, target) in clbit_map.iter() {
Expand Down Expand Up @@ -7579,15 +7579,7 @@ impl DAGCircuit {
}

pub fn add_global_phase(&mut self, value: &Param) -> PyResult<()> {
match value {
Param::Obj(_) => {
return 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)?)?,
}
Ok(())
self.set_global_phase(self.global_phase.try_add_scalar(value)?)
}

/// Return the op name counts in the circuit
Expand Down Expand Up @@ -8032,7 +8024,7 @@ impl DAGCircuit {
}
};

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

// This is all the handling we need for realtime variables, if there's no remapping. They:
//
Expand Down Expand Up @@ -8640,25 +8632,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"),
})
}

/// Update the tracking fields of the [DAGCircuit].
///
/// This is tightly coupled to the [DAGCircuit] internals and should be updated to match them, but
Expand Down
Loading