Hello! With great interest I read the demo about the dynamical lie algebra. I would like to calculate the dimension of the DLA for arbitrary generator sets. However, I struggle finding out if the elements of my current set of operators are linearly independent. In the demo example, this was straight forward and visible by eye. However, I was wondering if there is a smooth “pennylane” way of finding out if two operators are linearly independent, such that this algorithm below actually calculates the DLA:
import numpy as np
import pennylane as qml
from pennylane import X, Y, Z, I
from copy import deepcopy
qml.operation.enable_new_opmath()
# Generator Set for TFIM circuit with 3 qubits (also see https://arxiv.org/pdf/2105.14377.pdf Eq. 26 )
generators = [(1j + (Z(0) @ Z(1)) + (Z(1) @ Z(2))), 1j * X(0) + 1j * X(1) + 1j * X(2)]
# Following the terminology of the demo and the algorithm introduced in section E of this paper https://arxiv.org/abs/2105.14377
S = generators.copy()
"""Basis of the Lie algebra"""
S_new = (None,)
"""Set of matrices that was added to the Basis during the current iteration"""
S_prev = generators.copy()
"""Set of matrices that was added to the Basis during the last iteration"""
# algorithm:
while len(S_new) > 0:
# reset the array of matrices we have added to the basis
S_new = ()
for op1 in generators:
for op2 in S_prev:
# calculating the nested commutator
C = qml.commutator(op1, op2)/2
C = C.simplify()
# Pseudo Code:
# Question would be how to check for linear independence.
if LinearIndependance(C,*S):
S += (C,)
S_new += (C,)
S_prev = S_new
print('DLA:' S, 'and dim DLA:' len(S))
Thank you!