# QISKIT: ValueError: too many subscripts in einsum DensityMatrix()

I am trying to compute the entanglement entropy of a partition of a quantum system on qiskit. To do this, I call the function DensityMatrix(). If I go above 10 sites (e.g. 12), I get an error like:

ValueError: too many subscripts in einsum

Is there any workaround for this problem?

Here is the code:

#FIXED THETA STEP, BIPARTITION, varying p of theta/p

#Circuit parameters
n=8
steps = np.array(([1]))

#SPECIFY PARAMETERS
A=1;G=0;

#Define arrays
thetas= np.arange(0.001,10,0.1)
ent_entropy = np.zeros((len(steps),len(thetas)),dtype=complex)
renyi = np.zeros((len(steps),len(thetas)),dtype=complex)
subsystem = [j for j in range(0,n//2)]

for m,step in enumerate(steps):

for k,T in enumerate(thetas):
string = "0" * (n)
qc = QuantumCircuit(n)
QuantumCircuit.initialize(qc,string)

#init with Kareljan's state
qc.unitary(prodstaten(n), range(0,n))

matrix = U(A,T/step,G)
bwassembler(qc,matrix,1,n)

######################################################################
#access density matrix
rho = DensityMatrix(qc)
reduced_rho=partial_trace(rho, subsystem)

#find the eigenvalues of the reduced density matrix
eigenvalues, _ = np.linalg.eig(reduced_rho)

#compute the entanglement entropy
entanglement_entropy = -np.sum(eigenvalues * np.log(eigenvalues))
renyi[m,k]=-np.log(DensityMatrix.purity(reduced_rho))
ent_entropy[m,k]=entanglement_entropy
#print(k,ent_entropy[k])
######################################################################

• Can you please post your code as text instead of using a screenshot? It's easier for testing Nov 14 at 16:32
• Sure, I will edit the question now. Nov 14 at 17:51