When using large t and large Hamiltonians (observed for Hamiltonians with >5 qubits, t>10), the output of the function becomes an np.matrix instead of an np.array.
Consequently, np.dot() using the output matrix will crash for large t where it worked for small t.
e.g. the following will work for t=small_t and crash for t=large_t:
import hamiltonian_exponentiation as h
import numpy as np
small_t = 1
large_t = 15
some_hamiltonian = h.random_hamiltonian(5)
initial_state = np.array([1,0])
# This works:
U = h.exp_ham(some_hamiltonian, t=small_t)
evolved_state = np.dot(U, initial_state)
# This crashes:
U = h.exp_ham(some_hamiltonian, t=large_t)
evolved_state = np.dot(U, initial_state)
The crash will be of type
ValueError: shapes (64,) and (1,64) not aligned: 64 (dim 0) != 1 (dim 0)
becasue U is an np.matrix with shape (64, 64), whereas in order for np.dot to work while the second argument is an np.array with shape (64, ), the first argument also needs to be an np.array of shape (64, 64), i.e. not a matrix.
This will be fixed in the next update, but can be fixed by setting:
U = np.array(h.exp_ham(some_hamiltonian, t=large_t))
When using large t and large Hamiltonians (observed for Hamiltonians with >5 qubits,
t>10), the output of the function becomes annp.matrixinstead of annp.array.Consequently,
np.dot()using the output matrix will crash for large t where it worked for small t.e.g. the following will work for
t=small_tand crash fort=large_t:The crash will be of type
becasue
Uis annp.matrixwith shape(64, 64), whereas in order fornp.dotto work while the second argument is annp.arraywith shape(64, ), the first argument also needs to be annp.arrayof shape(64, 64), i.e. not a matrix.This will be fixed in the next update, but can be fixed by setting: