Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Nov 15, 2023
1 parent 19cf309 commit 214e775
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tket2-py/src/circuit/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ impl Tk2Circuit {
}

/// Encode the circuit as a HUGR json string.
//
// TODO: Bind a messagepack encoder/decoder too.
pub fn to_hugr_json(&self) -> PyResult<String> {
Ok(serde_json::to_string(&self.hugr).unwrap())
}
Expand Down Expand Up @@ -100,7 +102,9 @@ impl CircuitType {
}
}

/// Apply a fallible function expecting a hugr on a pytket circuit.
/// Apply a fallible function expecting a hugr on a python circuit.
///
/// This method supports both `pytket.Circuit` and `Tk2Circuit` python objects.
pub fn try_with_hugr<T, E, F>(circ: &PyAny, f: F) -> PyResult<T>
where
E: Into<PyErr>,
Expand All @@ -118,15 +122,20 @@ where
(f)(hugr, typ).map_err(|e| e.into())
}

/// Apply a function expecting a hugr on a pytket circuit.
/// Apply a function expecting a hugr on a python circuit.
///
/// This method supports both `pytket.Circuit` and `Tk2Circuit` python objects.
pub fn with_hugr<T, F>(circ: &PyAny, f: F) -> PyResult<T>
where
F: FnOnce(Hugr, CircuitType) -> T,
{
try_with_hugr(circ, |hugr, typ| Ok::<T, PyErr>((f)(hugr, typ)))
}

/// Apply a hugr-to-hugr function on a pytket circuit, and return the modified circuit.
/// Apply a fallible hugr-to-hugr function on a python circuit, and return the modified circuit.
///
/// This method supports both `pytket.Circuit` and `Tk2Circuit` python objects.
/// The returned Hugr is converted to the matching python object.
pub fn try_update_hugr<E, F>(circ: &PyAny, f: F) -> PyResult<&PyAny>
where
E: Into<PyErr>,
Expand All @@ -139,7 +148,10 @@ where
})
}

/// Apply a hugr-to-hugr function on a pytket circuit, and return the modified circuit.
/// Apply a hugr-to-hugr function on a python circuit, and return the modified circuit.
///
/// This method supports both `pytket.Circuit` and `Tk2Circuit` python objects.
/// The returned Hugr is converted to the matching python object.
pub fn update_hugr<F>(circ: &PyAny, f: F) -> PyResult<&PyAny>
where
F: FnOnce(Hugr, CircuitType) -> Hugr,
Expand Down

0 comments on commit 214e775

Please sign in to comment.