-
Notifications
You must be signed in to change notification settings - Fork 107
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
[UnitaryHack] Make ansatz class a training hyperparameter #101
Conversation
* main: Fix IBMAccountError
Hi Neil, thanks for your submission, it looks quite good already. I've enabled the tests to run on this PR, so would you be able to have a look at where they're failing and see if you could fix them up? |
Hi @ianyfan, thank you for the review. I just pushed a new commit to address the |
@ianyfan just saw the failing jobs related to the notebook tests and type checking - will push a fix to those soon. |
Thanks, noted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @neiljdo ,
Thanks for this PR!
it looks good in general, though I have some comments:
- The ansatz is applied to the diagrams at each epoch. This can slow down training a lot, especially for large datasets / diagrams. Instead, it would be better to save the train and val circuits as properties of the Trainer object during init and checkpoint-load.
- It would be good to add tests / manually test that all the ansatze are serialisable through pickle.
- It would be much better if the model did not take the test set as input during training, for a clear separation. This would be particularly natural once the UNK feature is completed. (UnitaryHACK: Replace unknown words in diagrams with
UNK
token #84) - Currently, the ansatz is a property of the Trainer, though it makes conceptual sense for this to be a property of the Model. In this case, it would be possible to make the
forward
andget_diagram_output
functions take a diagram as input, and apply the ansatz internally.
Since this is already a complex task and there are some design decisions involved, it would be great if you could address points 1 and 2 so the issue can be assigned to you for the hack.
The remaining points can be discussed later.
Would also be great if you could run the clean_notebooks.py script, which removes some metadata from the examples and tutorials. |
@nikhilkhatri,
For (3) and (4) above, I realized that the model is coupled with the circuits while working on the issue. I saw this more while updating the demo notebooks and saw that the |
@neiljdo you are correct in that the ansatze are deterministic. My point was to ensure that there are no Exceptions raised when pickling an ansatz class (for example, if they use a lambda function). |
w.r.t the lambda pickling, your code may be alright since it pickles the class, not the instance. It would still be good to make sure. |
May I drop a suggestion here? Based on what I understand from the code :
Since the dataset method is not run every time, I think it could be better if you make the circuits once, pass the list to _init_model_from_datasets method, and also use the list in the training and validation step (based on the index of the diagram of course). My suggestion is after fixing 1, to have the _init_model_from_datasets also have the reference from 1's fix. @nikhilkhatri dear, am I correct? Please correct me if I am wrong. |
Hi @ACE07-Sev , |
This allows for direct serialization of the ansatzes.
Hi @nikhilkhatri, I've addressed points (1) and (2) from your original comment in my latest update. Specifically,
Let me know if there are still issues, thank you very much! EDIT: I ran the |
Hi @neiljdo I have a couple of comments:
It would be great if you could address issues 1 and 2 for the hack. |
@nikhilkhatri |
Neil dear : lambeq/training/checkpoint.py:27: error: Cannot find implementation or library The test with pytest passed, so I think you just need to fix this import error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good work! The issue will be assigned to you, however the PR will be merged a little later.
Moved to lambeq's private repository for further development. This feature will be included in one of the upcoming releases. |
PR adds the ansatz class and necessary arguments for instantiation (e.g.
ob_map
and ansatz-specific kwargs) as hyperparameters to the trainer class. The functions related to creating and loading checkpoints have also been updated to accommodate the new ansatz class hyperparameter.Addresses #86.