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

Trainable flag for parametrized gates #294

Merged
merged 5 commits into from
Dec 15, 2020
Merged

Trainable flag for parametrized gates #294

merged 5 commits into from
Dec 15, 2020

Conversation

stavros11
Copy link
Member

This PR adds the trainable flag in all parametrized gates which allows the user to hide them from circuit.get_parameters() and circuit.set_parameters(). For example

c = Circuit(3)
c.add(gates.RX(0, theta=0))
c.add(gates.RY(1, theta=0.5, trainable=False))
c.add(gates.RZ(2, theta=0.8))

print(c.get_parameters()) 
# will print [0, 0.8] ignoring the RY

c.set_parameters([0.2, 0.4])
# will set RX(0.2) and RZ(0.4) and ignore RY

@scarrazza, @igres26 I used the name trainable for this flag following Tensorflow/Keras but I am open to alternative suggestions.

@codecov
Copy link

codecov bot commented Dec 10, 2020

Codecov Report

Merging #294 (18a8d14) into master (568bb2d) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #294   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           55        55           
  Lines        10583     10664   +81     
=========================================
+ Hits         10583     10664   +81     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/qibo/base/abstract_gates.py 100.00% <100.00%> (ø)
src/qibo/base/circuit.py 100.00% <100.00%> (ø)
src/qibo/base/gates.py 100.00% <100.00%> (ø)
src/qibo/tensorflow/cgates.py 100.00% <100.00%> (ø)
src/qibo/tensorflow/gates.py 100.00% <100.00%> (ø)
src/qibo/tests/test_parametrized.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 568bb2d...18a8d14. Read the comment docs.

Copy link
Member

@scarrazza scarrazza left a comment

Choose a reason for hiding this comment

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

Looks good and follows our discussion. I have just one comment about get_parameters, in some context would be useful to have something like get_parameters(include_not_trainable=True) to retrieve all parameters for a later circuit reallocation, e.g. when you store the best model parameters and then reload from file.

@stavros11
Copy link
Member Author

Looks good and follows our discussion. I have just one comment about get_parameters, in some context would be useful to have something like get_parameters(include_not_trainable=True) to retrieve all parameters for a later circuit reallocation, e.g. when you store the best model parameters and then reload from file.

Thanks for the review. I added this option to get_parameters.

@scarrazza scarrazza merged commit 824af84 into master Dec 15, 2020
@stavros11 stavros11 deleted the trainable branch January 18, 2021 12:39
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