Closed steve-jeffrey closed 1 year ago
Hi @steve-jeffrey, Thanks very much for the detailed issue. Does the code snippet fix you posted account for parameters supplied to gates?
Keeping each gate as a tuple of (label, *params, *regs)
, is pretty unsatisfactory I have to say, this might be a good moment to think about using a simple Gate
dataclass, with gate.label, gate.params, gate.regs, gate.size
etc. I will try and look into making this change.
Hi Johnnie,
No, it does not account for parameters.
The code snippet attempts to work backwards through the array, so it only picks up regs. I took this approach as: (i) I didn't know what the array contained (I thought the first element was the gate name/ID and the last elements were the regs, but I didn't know what else it could contain) and (ii): this approach seemed similar to the approach you used (I think you were checking only the last element in the array, or the last two elements). However, I think my code snippet will fail if the array contains parameters which are integers, as the code will assume the integer parameters are regs. Hopefully you can implement something better :-)
OK, I've added a much more robust Gate
class that should fix the issue (see commit above). Let me know if things aren't working.
It should be much easier to add custom gates and multi-qubit gates as well if you have particular things in mind.
It seems to be working fine. Thanks Johnnie.
What happened?
The tags in the reverse lightcone are computed when calling
quimb.tensor.circuit.Circuit.local_expectation()
.The calculation does not include gates that have more than 2 indices (e.g.
raw
gates defined by the user), consequently:where
index, and the gate has more than 2 indices, and the index matching thewhere
index is not one of the last two indices (the code fails because the light cone is empty).I have provided draft code which appears to fix the problem (it it is indeed a bug).
What did you expect to happen?
The lightcone should include all gates with indices matching the
where
index.Minimal Complete Verifiable Example
Relevant log output
Anything else we need to know?
I think the problem is due to this code block:
which appears to only take the last one or two indices in the
gate
array, which is insufficient when the gate has more than 2 indices.If the above block of code is replaced with this:
the tags appear to be computed correctly (at least on the example I provided above).
Environment
Quimb commit cf1898f (from 17 May 2022) Python 3.8.12 Fedora 35