-
Notifications
You must be signed in to change notification settings - Fork 1
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 support for multi-register circuit conversion #72
Conversation
@gcalin Hi, thanks for the PR! Could you provide an example that produces the problem? We do have a default |
@yao-cqc Thank you for looking into this. I am encountering this error when using a different compilation stack. Particularly, the workflow I am using is (1) building a circuit in I am new to |
Got you. The documentation for If you don't like the way how FlattenRegisters behaves, you also have the option to use |
For example: from pytket.extensions.qulacs.qulacs_convert import (
tk_to_qulacs,
)
from pytket.extensions.qulacs.backends import QulacsBackend
from pytket.circuit import Circuit, Qubit
c = Circuit()
reg_A = c.add_q_register("A", 1)
reg_B = c.add_q_register("B", 2)
c.CX(reg_A[0], reg_B[1])
# option 1: use the default compilation pass
b = QulacsBackend()
d = b.get_compiled_circuit(c, optimisation_level=0)
qulacs_circ = tk_to_qulacs(d)
# option 2: manually rename (assume that your circuit doesn't need rebase)
c.rename_units({
reg_A[0]: Qubit(0),
reg_B[0]: Qubit(1),
reg_B[1]: Qubit(2),
})
qulacs_circ = tk_to_qulacs(c) of course you can also call FlattenRegisters directly from pytket.passes import FlattenRegisters
FlattenRegisters().apply(c) |
Understood, thank very much you for the references and examples. In this case, would you be interested in extending the functionality of |
To make |
I removed my initial solution and replaced it with a conditional |
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.
Looks good, thank you @gcalin !
Description
Currently, the
tk_to_qulacs
function converts the indices of the qubits upon gates operate in an absolute manner, i.e., retrieve the qubit's index from its register. For example, for two qubit gates:As a result, circuits with multiple registers are not converted correctly. The corresponding Qulacs circuit that the function builds only has a single register, and
index_map
does not account for the register's position in the original tket circuit. I added two functions that build a dictionary in such a way that multiple registers are accounted for in the input circuit.