Skip to content

Conversation

@charlesyuan314
Copy link
Contributor

Add a bloq to copy a register in computational basis via CNOTs that can be used to simplify diagrams.

@charlesyuan314 charlesyuan314 changed the title Add Copy bloq Add Xor bloq Jul 17, 2024
Comment on lines 164 to 172

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)}

Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Falling back to Controlled().

Copy link
Contributor

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.

Copy link
Contributor

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.

@charlesyuan314 charlesyuan314 merged commit 7f3e929 into quantumlib:main Jul 17, 2024
@charlesyuan314 charlesyuan314 deleted the copy branch July 17, 2024 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants