'QNode' object has no attribute 'draw' in Trainable Quantum Convolution

I try to run Demo Trainable Quantum Convolution.ipynb offered from here in my google colab evironment.

There are two bugs in this workflow

①I get the following error when executing the third block


AttributeError Traceback (most recent call last)
in
2
3 qonv = QonvLayer(circuit_layers=1, n_rotations=8, out_channels=4, stride=2)
----> 4 qonv.draw()
5 x = torch.rand(size=(1,28,28,1))
6

in draw(self)
35 # build circuit by sending dummy data through it
36 _ = self.circuit(inputs=torch.from_numpy(np.zeros(4)))
—> 37 print(self.circuit.qnode.draw())
38 self.circuit.zero_grad()
39

AttributeError: ‘QNode’ object has no attribute ‘draw’


②I get the following error when executing the 8th block


AttributeError Traceback (most recent call last)
in
16
17 # start training
—> 18 model, losses, accs = train(model, train_loader, epochs=1)
19
20

1 frames
in train(model, train_loader, epochs)
45
46 if i % 5 == 0:
—> 47 model[0].draw()
48
49 print("---------------------------------------\n")

in draw(self)
35 # build circuit by sending dummy data through it
36 _ = self.circuit(inputs=torch.from_numpy(np.zeros(4)))
—> 37 print(self.circuit.qnode.draw())
38 self.circuit.zero_grad()
39

AttributeError: ‘QNode’ object has no attribute ‘draw’

Both errors show ‘QNode’ object has no attribute 'draw
.

I would like to know how to solve this problem.

See this sample code for details.
https://github.com/PlanQK/TrainableQuantumConvolution/blob/main/Demo%20Trainable%20Quantum%20Convolution.ipynb

Hi @TM_MEME!

It looks like this code is very old. I would recommend that you try using qml.draw_mpl(). In our documentation you can see examples of how to use it.

The simplest way to use it would be to write:
qml.draw_mpl(circuit)(parameters)

Where ‘circuit’ is the name of your circuit and ‘parameters’ are the parameters it takes. In your case it seems that ‘circuit’ is the name of the circuit and the parameters are ‘inputs’ and ‘weights’.

Please let me know if this is helpful!

Hi Catalina!
Thank you so much for your thoughtful response.
As you pointed out, there was a problem with the draw() function.
The code ran without error!

Thanks a lot for the draw_mpl introduction!

I’m glad this helped @TM_MEME :smiley:. Enjoy using PennyLane!