-
Notifications
You must be signed in to change notification settings - Fork 82
Add Xor bloq
#1149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Xor bloq
#1149
Conversation
|
|
||
| for i in range(len(xs)): | ||
| xs[i], ys[i] = bb.add_t(CNOT(), ctrl=xs[i], target=ys[i]) | ||
|
|
||
| return {'x': bb.join(xs), 'y': bb.join(ys)} | ||
|
|
||
| def build_call_graph(self, ssa: 'SympySymbolAllocator') -> Set['BloqCountT']: | ||
| return {(CNOT(), self.dtype.num_qubits)} | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to use a Toffoli() instead of a CNOT whenever self.control_val is not None. So this decomposition would be incorrect.
I think I take my suggestion back -- for a simple bloq like this, it's probably best to just let the Controlled() bloq handle the controlled version and it's cost instead of explicitly defining the controlled bloq. The advantages of having a custom controlled Bloq, as I see it, is mainly
a) More control over diagrams
b) Explicit control over decomposition and costings, though in this case that shouldn't matter.
@anurudhp Do you remember why you explicitly defined the controlled version for XorK in https://github.com/quantumlib/Qualtran/pull/1110/files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Falling back to Controlled().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually not sure, I think I had it initially to match AddK, but forgot to remove it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's best to avoid specialized controls unless we want to explicitly specify the diagrams for Xor and XorK. I'll cleanup the XorK bloq.
Add a bloq to copy a register in computational basis via CNOTs that can be used to simplify diagrams.