Skip to content
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

Merged
merged 7 commits into from
Aug 8, 2023

Conversation

chensgit169
Copy link
Collaborator

see qreg.py for details, to be incorporated into Circuit and visualisation.

Comment on lines 68 to 80
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])
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Comment on lines 59 to 62
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)
Copy link
Collaborator

@Zhaoyilunnn Zhaoyilunnn Aug 2, 2023

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__

Copy link
Collaborator Author

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.

chensgit169 and others added 4 commits August 8, 2023 10:53
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.
@Zhaoyilunnn Zhaoyilunnn merged commit e73b585 into ScQ-Cloud:master Aug 8, 2023
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants