Skip to content

Commit

Permalink
Fix: Make QuantumCircuitData public.
Browse files Browse the repository at this point in the history
- `QuantumCircuitData` is an extractor helper built only to extract attributes from a Python-based `Quantumircuit` that are not yet available in rust + the qualities that already are through `CircuitData`.
- Add `Clone` trait `QuantumCircuitData` as all its properties are clonable.
- Make `circuit_to_dag` public in rust in case it needs to be used for a transpiler pass.
- Adapt to renaming of `DAGCircuit::add_from_iter` into `DAGCircuit::extend`.
  • Loading branch information
raynelfss committed Sep 4, 2024
1 parent d48365b commit 71c8aa5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions crates/circuit/src/converters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ use crate::{circuit_data::CircuitData, dag_circuit::DAGCircuit};

/// An extractable representation of a QuantumCircuit reserved only for
/// conversion purposes.
///
/// ## Notes:
/// This structure does not implement `Clone`, this is the intended behavior as
/// it contains callbacks to Python and should not be stored anywhere.
#[derive(Debug)]
struct QuantumCircuitData<'py> {
#[derive(Debug, Clone)]
pub struct QuantumCircuitData<'py> {
data: CircuitData,
name: Option<Bound<'py, PyAny>>,
calibrations: Option<HashMap<String, Py<PyDict>>>,
Expand Down Expand Up @@ -63,7 +59,7 @@ impl<'py> FromPyObject<'py> for QuantumCircuitData<'py> {
}

#[pyfunction(signature = (quantum_circuit, copy_operations = true, qubit_order = None, clbit_order = None))]
fn circuit_to_dag(
pub fn circuit_to_dag(
py: Python,
quantum_circuit: QuantumCircuitData,
copy_operations: bool,
Expand Down
2 changes: 1 addition & 1 deletion crates/circuit/src/dag_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6638,7 +6638,7 @@ impl DAGCircuit {
.collect::<PyResult<Vec<_>>>()?;

// Finally add all the instructions back
new_dag.add_from_iter(py, instructions)?;
new_dag.extend(py, instructions)?;

Ok(new_dag)
}
Expand Down

0 comments on commit 71c8aa5

Please sign in to comment.