As noted by @pranav97nair and @thierry-martinez in #445 , PauliExponentialDAG.from_focused_flow requires the flow to be focused but does not verify this. When the flow is obtained from OpenGraph.extract_pauli_flow, we don't need such a check since Pauli-flow extraction always returns a focused Pauli flow by construction, but this may not hold for arbitrary user-constructed flows (and following the same logic, we don't even check that the flow is well-formed). The current approach merely relies on the function name from_focused_flow to indicate that the flow should be focused (and well-formed, of course).
Another option would be to run is_well_formed and is_focused systematically, but that would lead to unnecessary checks in the common cases where flows come from extract_pauli_flow. This could be circumvented by adding a flag check_valid_flow to be set to False when performance is needed, but adding boolean flags to determine the function's behaviour is in general not a good practice.
@thierry-martinez suggests introducing FocusedPauliFlow and FocusedGFlow classes to indicate that a flow is focused at the type level (although this may render the API overly complex).
A related research question is open: are flows obtained from patterns via Pattern.extract_gflow focused ?
As noted by @pranav97nair and @thierry-martinez in #445 ,
PauliExponentialDAG.from_focused_flowrequires the flow to be focused but does not verify this. When the flow is obtained fromOpenGraph.extract_pauli_flow, we don't need such a check since Pauli-flow extraction always returns a focused Pauli flow by construction, but this may not hold for arbitrary user-constructed flows (and following the same logic, we don't even check that the flow is well-formed). The current approach merely relies on the function namefrom_focused_flowto indicate that the flow should be focused (and well-formed, of course).Another option would be to run
is_well_formedandis_focusedsystematically, but that would lead to unnecessary checks in the common cases where flows come fromextract_pauli_flow. This could be circumvented by adding a flagcheck_valid_flowto be set toFalsewhen performance is needed, but adding boolean flags to determine the function's behaviour is in general not a good practice.@thierry-martinez suggests introducing
FocusedPauliFlowandFocusedGFlowclasses to indicate that a flow is focused at the type level (although this may render the API overly complex).A related research question is open: are flows obtained from patterns via
Pattern.extract_gflowfocused ?