-
Notifications
You must be signed in to change notification settings - Fork 36
Open
Labels
bugSomething isn't workingSomething isn't working
Description
TensorNetworkBackend
ignores the order of output nodes. The current implementation of finalize
is:
def finalize(self, output_nodes) -> None:
"""Do nothing."""
This means that the resulting tensor network returns a state vector in an unexpected order, as demonstrated by the following test, which currently fails.
@pytest.mark.parametrize(("nqubits", "jumps"), itertools.product(range(2, 6), range(1, 6)))
def test_to_statevector_order(self, fx_bg: PCG64, nqubits: int, jumps: int, fx_rng: Generator) -> None:
rng = Generator(fx_bg.jumped(jumps))
circuit = rand_circuit(nqubits, 3, rng)
pattern = circuit.transpile().pattern
pattern.standardize()
pattern.shift_signals()
statevec_ref = circuit.simulate_statevector().statevec
pattern.reorder_output_nodes(reversed(pattern.output_nodes))
tn = pattern.simulate_pattern("tensornetwork", rng=fx_rng)
statevec_tn = tn.to_statevector()
inner_product = np.inner(statevec_tn, statevec_ref.flatten().conjugate())
assert abs(inner_product) == pytest.approx(1)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working