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

[Draft] Code prototypes #24

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

[Draft] Code prototypes #24

wants to merge 34 commits into from

Conversation

Doomsk
Copy link
Member

@Doomsk Doomsk commented Oct 29, 2024

Writing all the code prototypes in Qadence 2 that @jpmoutinho is generating on Qadence 1.

Regardless the examples, some points to consider in the TODO list:
[ ] properly handle dtypes (João pointed out to include the set_default_dtype(torch.float64) in the __init__.py file of qadence2-core folder)
[ ] fix the issue with the inputs on the qadence2_platforms.backends.pyqtorch.embedding.Embedding.__call__ method containing variational parameters (variables) as well
[ ] replace dictionaries to OrderedDict on the inputs and/or variational parameters

@Doomsk Doomsk changed the title [Draft [Draft] Code prototypes Oct 29, 2024
@Doomsk Doomsk self-assigned this Oct 29, 2024
add extra functionalities to accommodate proper usage of the package

Signed-off-by: Doomsk <[email protected]>
add extra functionalities to accommodate proper usage of the package

Signed-off-by: Doomsk <[email protected]>
Signed-off-by: Doomsk <[email protected]>
fix minor mypy inconsistencies

Signed-off-by: Doomsk <[email protected]>
Signed-off-by: Doomsk <[email protected]>
Signed-off-by: Doomsk <[email protected]>
Signed-off-by: Doomsk <[email protected]>
Signed-off-by: Doomsk <[email protected]>
Signed-off-by: Doomsk <[email protected]>
Signed-off-by: Doomsk <[email protected]>
Signed-off-by: Doomsk <[email protected]>
Copy link
Contributor

@pimvenderbosch pimvenderbosch left a comment

Choose a reason for hiding this comment

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

Hi Eduardo, thank you for the good work on this PR. I have a few comments to be addressed.
Also, I see that the test suite doesn't have 100% coverage yet, could you have a look into the parts of the code that are not tested yet?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can this import + default type setting be pushed down into the pyqtorch subfolder? If you're using a different backend importing torch is not necessary.

values: dict[str, ArrayType] | None = None,
callback: Optional[Callable] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Docstring should reflect this change.

values: dict[str, ArrayType] | None = None,
shots: int | None = None,
callback: Optional[Callable] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Docstring should reflect this change

values: dict[str, ArrayType] | None = None,
observable: Any | None = None,
callback: Optional[Callable] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Docstring to be updated.

"""
Convert InputType object to Qutip native quantum objects for simulation on QuTiP.

It is intended to be used on expectation method of the Fresnel1 interface class.
Copy link
Contributor

Choose a reason for hiding this comment

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

used on the expectation method

from typing import Any, Protocol, runtime_checkable


@runtime_checkable
Copy link
Contributor

Choose a reason for hiding this comment

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

Why should the protocols in this module be runtime_checkable?

Comment on lines +76 to +82
if observable is not None:
return platform.expect(
obs_list=parse_native_observables(
num_qubits=len(self.sequence.register.qubit_ids), observable=observable
)
)
raise ValueError("observable cannot be None or empty on 'expectation' method.")
Copy link
Contributor

Choose a reason for hiding this comment

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

For reducing the number of indents:

Suggested change
if observable is not None:
return platform.expect(
obs_list=parse_native_observables(
num_qubits=len(self.sequence.register.qubit_ids), observable=observable
)
)
raise ValueError("observable cannot be None or empty on 'expectation' method.")
if observable is None:
raise ValueError("observable cannot be None or empty on 'expectation' method.")
return platform.expect(
obs_list=parse_native_observables(
num_qubits=len(self.sequence.register.qubit_ids), observable=observable
)
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be a good idea to group the tests per backend? This way they stay organized when there are many more backends implemented. Like so:

├── tests
│   ├── fresnel1
|   |   └── test_xxx.py
│   ├── pyqtorch
|   |   └── test_yyy.py

This way the folder structure also matches more closely with the source structure.

An additional suggestion is to define conftest.py per backend for fixtures that are backend specific.

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