Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CircuitGraph allows the same operation instance to occur multiple tim…
…es (#5907) **Context:** `CircuitGraph` is from the early queuing era, when we could trust that every operation in a circuit was unique, since queuing had that constraint. This is no longer the case, and can cause errors when the same operation is repeated multiple times. For example, in `TrotterProduct.compute_decomposition`. **Description of the Change:** The nodes of the `CircuitGraph` are now the indices into the queue. Indices will be fully unique, even if the same operation occurs multiple times. This is accomplished in conjunction with two new private attributes: * `_nodes_on_wires`: a dictionary mapping a wire to the nodes that are on that wire * `_inds_for_objs`: a dictionary mapping a `WrappedObj` instance to all the indices where that instance occurs. This is a more general successor to `Operator.queue_idx`. By making this information a private attribute on `CircuitGraph`, we won't have conflicts if the same operation instance occurs in multiple different tapes/ graphs. The private properties `_grid` , `_indices`, and `_operation_graph` are removed, as they are no longer needed. The private method `_in_topological_order` is removed, since it was a private method that nothing used. `graph.operations_in_order` and `graph.observable_in_order` now just return `graph.operations` and `graph.observables` respectively, since those lists are already in order. It was basically "sort this list by the order the objects come in the list". They already come in the order that they come in the list? `_depth` and `max_simultaneous_measurements` are now cached properties. The method for calculating the depth is also simplified. Now we simply provide a weight function on the edges to `rx.dag_longest_path_length`. **Benefits:** We can use the same instance multiple times in a `CircuitGraph` object. **Possible Drawbacks:** `CircuitGraph` no longer sets `Operator.queue_idx`. Maybe someone wanted that. The nodes for `CircuitGraph` are now integer indices, rather than operations. So anyone relying on the individual nodes will see a change in behavior. **Related GitHub Issues:** Fixes #4406 [sc-42719] --------- Co-authored-by: Astral Cai <[email protected]> Co-authored-by: Mudit Pandey <[email protected]> Co-authored-by: Cristian Emiliano Godinez Ramirez <[email protected]>
- Loading branch information