From 48290a22086e83b092e6eccab54689f0614aec64 Mon Sep 17 00:00:00 2001 From: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:40:54 -0400 Subject: [PATCH] Fix: Use `is` to avoid obtaining the gil. - Remove `Display` trait. --- crates/circuit/src/operations.rs | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/crates/circuit/src/operations.rs b/crates/circuit/src/operations.rs index c990d4539805..f1706373e6d5 100644 --- a/crates/circuit/src/operations.rs +++ b/crates/circuit/src/operations.rs @@ -177,38 +177,13 @@ impl PartialEq for Param { fn eq(&self, other: &Self) -> bool { match (self, other) { (Param::Float(s), Param::Float(other)) => s == other, - (Param::ParameterExpression(one), Param::ParameterExpression(other)) => { - compare(one, other) - } - (Param::Obj(one), Param::Obj(other)) => compare(one, other), + (Param::ParameterExpression(one), Param::ParameterExpression(other)) => one.is(other), + (Param::Obj(one), Param::Obj(other)) => one.is(other), _ => false, } } } -impl std::fmt::Display for Param { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let display_name: String = Python::with_gil(|py| -> PyResult { - match self { - Param::ParameterExpression(obj) => obj.call_method0(py, "__repr__")?.extract(py), - Param::Float(float_param) => Ok(format!("Parameter({})", float_param)), - Param::Obj(obj) => obj.call_method0(py, "__repr__")?.extract(py), - } - }) - .unwrap_or("None".to_owned()); - write!(f, "{}", display_name) - } -} - -/// Perform comparison between two Python objects -pub fn compare(one: &PyObject, other: &PyObject) -> bool { - Python::with_gil(|py| -> PyResult { - let other_bound = other.bind(py); - Ok(other_bound.eq(one)? || other_bound.is(one)) - }) - .unwrap_or_default() -} - #[derive(Clone, Debug, Copy, Eq, PartialEq, Hash)] #[pyclass(module = "qiskit._accelerate.circuit")] pub enum StandardGate {