0 votes
asked by (240 points)

Hi Matt and Miles,

I have a simple question about the diagTensor and delta.

If I create a tensor using the diagTensor or delta method, then use the .set() method to modify a diagonal entry, will that change the sparse storage of the original tensor?

Best,

1 Answer

0 votes
answered by (14.1k points)

It looks like right now .set() is not defined for diagonal storage, i.e.:

auto i = Index("i",2);
auto j = Index("j",2);
auto A = delta(i,j);
A.set(i(1),j(1),2.0);

throws an error:

terminate called after throwing an instance of 'itensor::ITError'
  what():  doTask not defined for task SetElt and storage type DiagReal

From what I can tell, right now the only methods for actually modifying ITensors with Diag storage are .apply() and .fill(), so for example:

A.apply([](Real x){ return 2*x; });

would double all of the values of the diagonals, and

A.fill(3.);

would set all of the values to 3.

For more complicated element setting, you may have to store the original diagonal values (for example in a vector), manipulate them, and then use them in a diagTensor constructor to make a new ITensor with the diagonal values you want.

I think it would be good for us to define .set() for Diag/QDiag storage, and have it throw an error if a user tries to set an off-diagonal element. But I think many current cases can be covered by the current functionality, and worse case would be making a new diagTensor.

What is your particular use-case? Note that there is also a new iterInds function (http://www.itensor.org/support/1361/iterating-over-non-zero-elements-of-a-sparse-itensor) that can help you visit all of the elements of an ITensor, in case that helps.

Cheers,
Matt

commented by (70.1k points)
Yes, I would agree it's odd that .set isn't even defined for that storage type. I thought I had defined it! We could make it succeed if the element is diagonal and throw an error otherwise

The other thing we could add is a function that converts sparse tensors to dense in case users really want to set an element that's otherwise forced to be zero.
commented by (14.1k points)
Yeah, I think those are both functions we should add. I made this issue:
https://github.com/ITensor/ITensor/issues/176
to collect sparse storage operations that we should add.
Welcome to ITensor Support Q&A, where you can ask questions and receive answers from other members of the community.

Formatting Tips:
  • To format code, indent by four spaces
  • To format inline LaTeX, surround it by @@ on both sides
  • To format LaTeX on its own line, surround it by $$ above and below
  • For LaTeX, it may be necessary to backslash-escape underscore characters to obtain proper formatting. So for example writing \sum\_i to represent a sum over i.
If you cannot register due to firewall issues (e.g. you cannot see the capcha box) please email Miles Stoudenmire to ask for an account.

To report ITensor bugs, please use the issue tracker.

Categories

...