Skip to content

Commit c4d8bee

Browse files
authored
Use rust-native errors in DAGCircuit (#16134)
* Use rust-native errors in `DAGCircuit` This should be step 1 for splitting `PyDAGCircuit` from `DAGCircuit`. The following commits assure that any rust accessible method for `DAGCircuit` that: 1. Does not take a `py` token; 2. Is a public method. does not need to depend on `PyErr` to process any errors. It is ensured that these errors: - Maintain the level of detail that the previous ones did. - Correctly map to the same Python exceptions as before. The enumeration for these errors is called `DAGCircuitInnerError` (subject to change) and is implemented with `thiserror`. I chose this over `anyhow` because it is better for specifying where the error comes from based on its variant rather than the message it contains. * Lint: Use names instead of underscores * Add: `anyhow!` usage for `DAGCircuitError - Use `anyhow!` for any error types that don't require tracking of any variables coming from the `DAG` or that are part of the function arguments. - Consolidate the amount of `DAG` error variants down from 40+ to 21. Can be consolidated further. * Fix: Existing error formatting - Use `this_error` to fix the formatting of current errors causing conflicts with their messages. - Add `is_var` argument to differentiate Variables and Stretches in `VariableNotInlined`. * Fix: consolidate `RegistryAbsentObject` error. * Add: errors for `size` and `depth`. * Refactor: `DAGCircuitInnerError` to `DAGError` * Fix: Add custom `From` impl for `Infallible` - The new implementation elides `Infallible` by using a 0-variant `match` which will be valid only with `Infallible` and return nothing. * Fix: Add context to `WireOutOfRange` - Remove usage of `anyhow` for `WireOutOfRange`. * Remove: `anyhow` in `General errors We removed `anyhow` from the circuit crate and instead assumed any error of type `String` should be assigned to a `General` error. * Rename: `RegisterRef`, `ConcreteWire` to `RegisterType`, `ShareableWire`. * Fix: Incorrect use of qubits for clbit error * Revert: Hiding Py tokens in classical resources. * Fix: `panic!` when `"not a dag"` is found. * Revert: Original bits not idle error.
1 parent 3767817 commit c4d8bee

5 files changed

Lines changed: 477 additions & 324 deletions

File tree

crates/circuit/src/circuit_instruction.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ impl CircuitBlock for CircuitData {
595595
impl CircuitBlock for DAGCircuit {
596596
fn extract_py_block(ob: Bound<PyCircuitData>) -> PyResult<Self> {
597597
Self::from_circuit_data(&ob.borrow().inner, false, None, None, None, None)
598+
.map_err(Into::into)
598599
}
599600
}
600601
impl CircuitBlock for NoBlocks {

crates/circuit/src/converters.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub fn circuit_to_dag(
102102
qubit_indices,
103103
clbit_indices,
104104
)
105+
.map_err(Into::into)
105106
}
106107

107108
/// Convert a :class:`.DAGCircuit` to a :class:`.PyCircuitData`.

0 commit comments

Comments
 (0)