-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom operation first implementation
- Loading branch information
1 parent
b5af92d
commit bba581d
Showing
2 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
import tensorflow as tf | ||
import numpy as np | ||
from qibo import Circuit, gates | ||
|
||
|
||
@tf.custom_gradient | ||
def custom_operation(): | ||
output = | ||
|
||
def grad_fn() | ||
|
||
|
||
return output, grad_fn | ||
|
||
|
||
|
||
class MyLayer(tf.keras.layers.Layer): | ||
|
||
def __init__(self): | ||
super(MyLayer, self).__init__(): | ||
self.circuit = self.circuit() | ||
|
||
self.weights = self.add_weights(name='w', shape=(4,), initializer="random_normal") | ||
|
||
|
||
def circuit(self): | ||
c = Circuit(2) | ||
c.add(gates.X(0)) | ||
c.add(gates.RX(1, theta=0.5)) | ||
|
||
def call(self, x): | ||
self.circuit() | ||
|
||
def |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters