-
Notifications
You must be signed in to change notification settings - Fork 24
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 cls Qubit and QuantumRegister #46
Conversation
src/quafu/circuits/qreg.py
Outdated
if __name__ == '__main__': | ||
# q0 = Qubit(0) | ||
# q1 = Qubit(1) | ||
# reg = {q.pos: q for q in [q0, q1]} | ||
# print(reg) | ||
# | ||
# reg[0], reg[1] = reg[1], reg[0] | ||
# reg[0].pos, reg[1].pos = reg[1].pos, reg[0].pos | ||
# | ||
# print(reg) | ||
# print([q0.pos, q1.pos]) | ||
reg = QuantumRegister(4, name='reg') | ||
print(reg[3]) |
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.
Suggest not to put test/example code here.
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.
Yes, this part has been removed.
src/quafu/circuits/qreg.py
Outdated
def __add__(self, other: 'QuantumRegister'): | ||
qreg = QuantumRegister(name=self.name) | ||
qreg.qubits = {**{self.qubits}, **{i + len(self): qubit for i, qubit in other.qubits.item()}} | ||
return QuantumRegister(len(self) + len(other), name=self.name) |
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.
Can we have an inplace method, i.e., not to create a new cls
sth like this: self.qubits.update({i + len(self): qubit for i, qubit in other.qubits.items()})
, define an __iadd__
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.
Of course, yet this function was merely defined here as a reminder for future development. Let's see whether it will be actually needed.
Yet decorator implementation may be adopted in the future to provide cleaner coding and more flexible usage.
Yet decorator implementation may be adopted in the future to provide cleaner coding and more flexible usage.
see qreg.py for details, to be incorporated into Circuit and visualisation.