How to convert program (write by python and tf) to quantum program?

Dear Everyone,

I have a simple speech transmission program that wirite by python and tensorflow.
it includes three main parts such as: Encoding part, transsimision channel (e.g, wireless channel) part, and Decoding part.
For example of code source for encoding part:

def init(self, frame_length, stride_length, arg):
self.num_frame = args.num_frame
self.frame_length = frame_length
self.stride_length = stride_length
def call(self, _input):

    # preprocessing _intput
    _input, batch_mean, batch_var = wav_norm(_input)
    _input = enframe(_input, self.num_frame, self.frame_length, self.stride_length)
    _input = tf.expand_dims(_input, axis=-1)
    _output = conv_bn_layer(_input, filters=self.sem_enc_outdims[0],
                            strides=(2, 2), name="sem_enc_cnn1")
    _output = tf.nn.relu(_output)
    _output = conv_bn_layer(_output, filters=self.sem_enc_outdims[1],
                            strides=(2, 2), name="sem_enc_cnn2")
    _output = tf.nn.relu(_output)
    return _output, batch_mean, batch_var

Now, I want to convert all to quantum program.
Who can give me some suggesion/advisor to mine can complete it?

Hey @baba_tnvn, welcome to the forum! :rocket:

A great place to start is our demos: Demos | PennyLane

There’s a bunch there, but the quantum machine learning ones are good to start with: PennyLane — Results

In particular, this one about integrating PennyLane and Tensorflow: Turning quantum nodes into Keras Layers | PennyLane Demos

Let me know if that helps!

Dear @isaacdevlugt ,
Thank for your reply, I saw it and practice following with Quanvolutional Neural Networks demo.
I have a question. I have one convolution layer that defined likes

def conv_bn_layer(inputs, filters, strides, name):
    conv = Conv2D(filters=filters, kernel_size=(3, 3), strides=strides,
                  padding="same", use_bias=False, name="{}_conv".format(name))(inputs)
    conv_bn = BatchNormalization(name="{}_bn".format(name))(conv)
    return conv_bn

After I quantum this layer, can I use it to compute for other program (note that, this program is classical program)

It seems like that later is purely classical? In that sense, you can’t really make it quantum. PennyLane’s QNN functionality is meant to do the opposite: make quantum circuits “behave” like classical layers :slight_smile:.

Hi @isaacdevlugt,

This program is purely classical, My main target is want to convert it to quantum.
Please, can you share with me steps to do that?

Thank you so much, sir

Hey @baba_tnvn as far as I’m aware, there’s no general way to embed a purely classical layer onto a quantum circuit. Even if there is, I don’t think it would be that efficient :thinking:

I think you should look into how you can trick a quantum layer to behaving like a classical layer. This demo that I shared earlier goes into how that’s possible: Turning quantum nodes into Keras Layers | PennyLane Demos

Let me know if that helps!