Open kjm538 opened 1 month ago
Can you describe the action you want in more detail? If you want to flip the target when all control bits are ON (or in any given specification), you can look at MultiAnd
bloq which is equivalent an n-controlled Toffoli gate.
The other possibility, which I think is what you actually want, is to compare two n-bit registers (say x & y) and check whether they are the same, -- so a bloq that implements result = all(x[i] == y[i] for i in range(self.bitsize))
; or in your case result = all(x[i] != y[i] for i in range(self.bitsize))
. This is a quantum-quantum comparator and can be reduced to an XOR (N CNOT gates) followed by a quantum -classical comparison with 0 (i.e. a MultiAnd
) gate. Qualtran has bloqs for Xor
and MultiAnd
which can be used to implement your bloq.
The action I want is to flip the target bit if any of the controls are satisfied. So something like result = any(x[i] != y[i] for i in range(self.bitsize))
, however I only expect this to be True for one value of i
for any input state due to the way I've prepared the control register.
More explicitly, I'm implementing the decomposition for TestNuLessThanMu
in the first quantized block encoding. So the control register here corresponds to mu and the ancilla to one dimension of nu. In reality I have a series of MultiAnds with 4 controls ( the 1 on mu and three 0s on nu). Before this series of MultiAnds, the control/mu register has been prepared in a superposition of one-hot unary states.
Consider the following bloq which yields one And gate per qubit in the control register, all with the same target.
At first this may seem wrong since the target of the And gate must be clean by definition, and trying to decompose this bloq does lead to the error
which I think is due to this reason. However, if I have prepared my control register such that it's in a state where only one bit is 1 (ie |01> + |10> for bitsize=2), then algorithmically this construction is okay since the target will only be turned 'ON' once per state. A simple solution would be to just build my bloq using the Toffoli, however this is not ideal for resource counting purposes. Do you have any suggestions or thoughts on how to construct this?