get_ctrl_system is responsible for tracking which are the new soquets introduced to control the bloq and which are the existing ones. Since CNOT already has a control bit, we weave in the new control bit into the two bits in the ctrl register in Toffoli. Seemingly, at the beginning of the method I wanted to plug the new control bit into the second entry in the ctrl register but at the end of the method I thought I used the first entry in the ctrl register.
This is not an invalid thing to do for a general CompositeBloq but it is wrong for wiring up a Controlled(CNOT()). I added a unit test. The first assertion always passed. The second two previously failed. One needs to exercise Controlled([cbloq containing CNOT]).decompose_bloq() to see the bad behavior.
Fixes #1065
get_ctrl_system
is responsible for tracking which are the new soquets introduced to control the bloq and which are the existing ones. Since CNOT already has a control bit, we weave in the new control bit into the two bits in thectrl
register inToffoli
. Seemingly, at the beginning of the method I wanted to plug the new control bit into the second entry in the ctrl register but at the end of the method I thought I used the first entry in the ctrl register.This is not an invalid thing to do for a general
CompositeBloq
but it is wrong for wiring up a Controlled(CNOT()). I added a unit test. The first assertion always passed. The second two previously failed. One needs to exerciseControlled([cbloq containing CNOT]).decompose_bloq()
to see the bad behavior.