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

[Bugfix] Tensor representation of controlled operations with qubit support order #40

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

chMoussa
Copy link
Collaborator

Resolves #35

@chMoussa chMoussa added the bug Something isn't working label Jan 10, 2025
@chMoussa chMoussa self-assigned this Jan 10, 2025
@chMoussa chMoussa marked this pull request as ready for review January 10, 2025 12:49
Copy link
Collaborator

@RolandMacDoland RolandMacDoland left a comment

Choose a reason for hiding this comment

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

Hey thanks @chMoussa. Few comments from my side.

@@ -61,11 +62,41 @@ def tree_unflatten(cls, aux_data: Any, children: Any) -> Any:
return cls(*children, *aux_data)

def unitary(self, values: dict[str, float] = dict()) -> Array:
Copy link
Collaborator

Choose a reason for hiding this comment

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

It doesn't seem like values is used anywhere in this method unless I'm wrong ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, it is mostly picked up later by Parametric. We need to revisit these classes at some point.

return _dagger(self.unitary(values))

def tensor(self, values: dict[str, float] = dict()) -> Array:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, it feels like the semantics between unitary and tensor are close enough to be merged ? Is there a need for two methods ? It feels a bit like an overkill though.

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 it is a bit ill-defined but basically, in the apply functions, a different _controlled function is used that avoid permuting according to the qubit order, as it is not required to apply an operator. However, .tensor is required for Qadence, and especially for block_to_tensor.

Comment on lines +174 to +175
target_qubits: TargetQubits,
control_qubits: ControlQubits,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a need for two types 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.

It is legacy. Want to remove it?

Comment on lines +191 to +193
if isinstance(control_qubits[0], tuple):
controls = control_qubits[0]
if isinstance(target_qubits[0], tuple):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it mean that control_qubits and target_qubits could be tuples of tuples ?

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, legacy again for being able to sum them for the reduce operator a previous person wrote before me.

horqrux/utils.py Outdated Show resolved Hide resolved
control_ind_support = tuple(i for i, q in enumerate(qubit_support) if q in controls)

# Create the full Hilbert space dimension
full_dim = 2**ntotal_qubits
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
full_dim = 2**ntotal_qubits
full_dim = 2 ** ntotal_qubits

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lint does not agree with you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Controlled operations are not right
2 participants