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

Support for parameterization upper and lower bounds? #320

Closed
isurulucky opened this issue Nov 12, 2024 · 3 comments · Fixed by #325
Closed

Support for parameterization upper and lower bounds? #320

isurulucky opened this issue Nov 12, 2024 · 3 comments · Fixed by #325
Labels
enhancement New feature or request

Comments

@isurulucky
Copy link
Collaborator

Hi,

Right now, the Parameterization class takes the arguments initialization, activation and dtype [1]. If there is a requirement to specify upper and/or lower limits to the circuit parameter values, is there a way of doing it? AFAIU, the Parameterization class should carry this additional arguments, or is there a better way?

Some symbolic level parameter classes (ex.: ClampParameter [2]) already exist for actual clamping, I think we only need to pass the additional information about min/max values from the definition of the symbolic circuit.

[1]. https://github.com/april-tools/cirkit/blob/main/cirkit/templates/circuit_templates/utils.py#L35-L44

[2]. https://github.com/april-tools/cirkit/blob/main/cirkit/symbolic/parameters.py#L563

Thanks,
Isuru

@isurulucky isurulucky added the enhancement New feature or request label Nov 12, 2024
@loreloc
Copy link
Member

loreloc commented Nov 18, 2024

Hi Isuru,
we already have a "positive-clamp" parameterization. You can see it here:
https://github.com/april-tools/cirkit/blob/main/cirkit/templates/circuit_templates/utils.py#L169-L172
However, if you want to also specify min/max values, you would need to change the Parameterization class as to allow this extra parameters. For instance, we could have an activation_kwargs dictionary in Parameterization that takes the extra arguments, and are then passed to the chosen activation initialization.

If you want even more control on the parameterization, then I suggest using the Circuit.from_region_graph method to specify layer factories and sum weight factories.
https://cirkit-docs.readthedocs.io/en/latest/api/cirkit/symbolic/circuit/?h=from_region_g#cirkit.symbolic.circuit.Circuit.from_region_graph

@isurulucky
Copy link
Collaborator Author

Hi @loreloc ,

Thank you for the reply and the info.

I will check out the Circuit.from_region_graph method.

we already have a "positive-clamp" parameterization. You can see it here: https://github.com/april-tools/cirkit/blob/main/cirkit/templates/circuit_templates/utils.py#L169-L172 However, if you want to also specify min/max values, you would need to change the Parameterization class as to allow this extra parameters. For instance, we could have an activation_kwargs dictionary in Parameterization that takes the extra arguments, and are then passed to the chosen activation initialization.

I actually tried out the same earlier. If you think this is something good to have in addition to capabilities of Circuit.from_region_graph, I can send a PR.

BR,
Isuru

@loreloc
Copy link
Member

loreloc commented Nov 25, 2024

Hi Isuru,
I think it is a good idea. If you have a time for this, please feel free to open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants