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

[Feature, Testing] Allow nested calls to ConcretizedCallable, more tests #275

Merged
merged 26 commits into from
Oct 10, 2024

Conversation

jpmoutinho
Copy link
Collaborator

@jpmoutinho jpmoutinho commented Aug 30, 2024

Extends the ConcretizedCallable to allow nested calls, adds some convenience functions. E.g. now we can write

import pyqtorch as pyq

## Creating an expression and embedding

expr = "z" ** pyq.log(1.0 / (1.0 + (2.0 * pyq.sin("x")) + "y"))

expr_name = "expr"

embedding = pyq.Embedding(
    fparam_names = ["x", "y"],
    vparam_names = ["z"],
    var_to_call = {"expr": expr}
)

## Passing the expression to a block parameter

op = pyq.Scale(pyq.I(0), "expr")

values = {"x": torch.tensor(1.0), "y": torch.tensor(-1.0),  "z": torch.tensor(2.0)}

matrix = op.tensor(values, embedding)

matrix[..., 0]

---

tensor([[0.6971, 0.0000],
        [0.0000, 0.6971]])

Furthermore, with the current change, we might not need the Embedding 🤔. To be explored in a later MR: #278

@jpmoutinho jpmoutinho added feature New feature or request testing labels Aug 30, 2024
@jpmoutinho jpmoutinho self-assigned this Aug 30, 2024
Copy link
Collaborator Author

@jpmoutinho jpmoutinho left a comment

Choose a reason for hiding this comment

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

Thanks @vytautas-a :)

I think my main question is regarding the logic on how to write HamiltonianEvolution, and which are the correct combinations of parameters to write a time-dependent one, time-independent one, etc.

pyqtorch/hamiltonians/evolution.py Show resolved Hide resolved
pyqtorch/hamiltonians/evolution.py Outdated Show resolved Hide resolved
pyqtorch/hamiltonians/evolution.py Outdated Show resolved Hide resolved
pyqtorch/primitives/parametric.py Show resolved Hide resolved
pyqtorch/utils.py Show resolved Hide resolved
pyqtorch/hamiltonians/evolution.py Outdated Show resolved Hide resolved
pyqtorch/primitives/parametric.py Show resolved Hide resolved
pyqtorch/utils.py Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@jpmoutinho jpmoutinho left a comment

Choose a reason for hiding this comment

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

Thanks @vytautas-a, almost there but I think we should keep the usage of ConcretizedCallable as a parameter in the Parametric as well for consistency, since you added it to the Scale.

tests/test_analog.py Show resolved Hide resolved
pyqtorch/composite/compose.py Show resolved Hide resolved
pyqtorch/composite/compose.py Show resolved Hide resolved
pyqtorch/embed.py Show resolved Hide resolved
pyqtorch/hamiltonians/evolution.py Outdated Show resolved Hide resolved
pyqtorch/primitives/parametric.py Show resolved Hide resolved
@vytautas-a vytautas-a self-requested a review October 10, 2024 13:45
@vytautas-a vytautas-a merged commit 1d2a3a6 into main Oct 10, 2024
9 checks passed
@vytautas-a vytautas-a deleted the jm/embed_tests branch October 10, 2024 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants