From e8acd637ed920ad38b37ccb17a5cff9940c14a11 Mon Sep 17 00:00:00 2001 From: Marquess Valdez Date: Mon, 25 Mar 2024 14:06:53 -0700 Subject: [PATCH] cleanup instruction module, add comment explaining deepcopy --- rust/src/instruction/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rust/src/instruction/mod.rs b/rust/src/instruction/mod.rs index 779a0e542..29fc20bf4 100644 --- a/rust/src/instruction/mod.rs +++ b/rust/src/instruction/mod.rs @@ -67,6 +67,10 @@ impl Instruction { inner: self_.inner.clone(), }; + // QubitPlaceholders are implemented with Arc and identified as unique by their pointer + // address. Since cloning an Arc just copies the pointer address, we have to create new + // placeholders for the copy, otherwise resolving a placeholder in the copy would also + // resolve them in the original (or vice-versa). let mut placeholders: HashMap< quil_rs::instruction::QubitPlaceholder, quil_rs::instruction::QubitPlaceholder, @@ -91,7 +95,10 @@ impl Instruction { self.clone() } - /// + // This will raise an error if the program contains any unresolved + // placeholders. This is because they can't be converted to valid quil, + // nor can they be serialized and deserialized in a consistent + // way. pub fn __getstate__<'a>(&self, py: Python<'a>) -> PyResult> { Ok(PyBytes::new_bound( py,