Describe the feature you'd like
Hey all, I'm interested if there is any (efficient) way to get the unitary implemented from a given pattern. I did not find any direct function but I think this could be done easily if one can set the input state arbitrarily (issue #53) and check for flow of a pattern.
Additional context
I would propose a (pseudo) code in that direction:
def get_unitary_from_pattern(pattern):
# check if given pattern has flow, i.e. it implements indeed a unitary
assert has_flow(pattern)
# num_qubits .. defined via input/ouput nodes
assert pattern.num_input_nodes == pattern.num_output_nodes
num_qubits = pattern.num_input_nodes
N = 2**num_qubits
#----- get unitary -----
# do <i|U|j>=U_ij, where |n>=(0, .., 1, .., 0) std-basis
# maybe the lib (tensornetwork) allows a more efficient way?
U = np.zeros((N, N), dtype=np.complex128)
for j in range(N): #can be async
# set |j> input
state_j = np.zeros((N), dtype=np.complex128)
state_j[j] = 1
pattern.set_input(state_j)
# get matrix elements
tn = pattern.simulate_pattern(backend='tensornetwork')
state_U_j = tn.to_statevector()
U[:, j] = state_U_j
#same as
#for i in range(N): U[i, j] = state_U_j[i]
return U
Maybe there is a better way to do this? Maybe even with the current code base?
Describe the feature you'd like
Hey all, I'm interested if there is any (efficient) way to get the unitary implemented from a given pattern. I did not find any direct function but I think this could be done easily if one can set the input state arbitrarily (issue #53) and check for flow of a pattern.
Additional context
I would propose a (pseudo) code in that direction:
Maybe there is a better way to do this? Maybe even with the current code base?