# Problem using Cirq Plugin as Backend

**URL:** <https://discuss.pennylane.ai/t/problem-using-cirq-plugin-as-backend/274>\
**Category:** PennyLane Plugins\
**Created:** [November 21, 2019, 7:45pm UTC](https://discuss.pennylane.ai/t/problem-using-cirq-plugin-as-backend/274 "2019-11-21T19:45:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![thegajan](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@thegajan](https://discuss.pennylane.ai/u/thegajan)\
**Post date:** [November 21, 2019, 7:45pm UTC](https://discuss.pennylane.ai/t/problem-using-cirq-plugin-as-backend/274/1 "2019-11-21T19:45:13Z")

</div>

Tried running the [Data-reuploading classifer](https://pennylane.ai/qml/app/tutorial_data_reuploading_classifier.html) example, but changed the backend to cirq by doing the following:  
dev = qml.device(“cirq.simulator”, wires=1)

I am getting the following error:

 ![image](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/1X/495a914de60801badbbd1ed565014026a7bc7ea0.png)

I am not sure how to fix this issue but my goal is to build a similar sort of netowrk using Cirq backend.

Thanks in advance for the help!  
G

---

<div class="post-metadata">

**Author:** ![josh](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/josh/32/100_2.png) [@josh](https://discuss.pennylane.ai/u/josh)\
**Post date:** [November 21, 2019, 7:47pm UTC](https://discuss.pennylane.ai/t/problem-using-cirq-plugin-as-backend/274/2 "2019-11-21T19:47:23Z")

</div>

Hi @thegajan! I believe the Cirq plugin uses `dev.state` instead of `dev._state`. So replacing all occurances of `dev._state` with `dev.state` should fix the issue 🙂

This is something that we have on our roadmap to standardize, so by the next PennyLane release, all plugins should use the same attributes for states.

Let me know if that works!

---

<div class="post-metadata">

**Author:** ![thegajan](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@thegajan](https://discuss.pennylane.ai/u/thegajan)\
**Post date:** [November 21, 2019, 8:42pm UTC](https://discuss.pennylane.ai/t/problem-using-cirq-plugin-as-backend/274/3 "2019-11-21T20:42:00Z")

</div>

Fixed! Thanks for the help!  
@josh however, now when I run the model now performance suffers greatly.

 ![image](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/1X/1e39ed6a980466421781529b46480d4d3813ebc1.jpeg)

Is there a reason why Cirq backend performs so much worse than the default?

---

<div class="post-metadata">

**Author:** ![josh](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/josh/32/100_2.png) [@josh](https://discuss.pennylane.ai/u/josh)\
**Post date:** [November 22, 2019, 2:40am UTC](https://discuss.pennylane.ai/t/problem-using-cirq-plugin-as-backend/274/4 "2019-11-22T02:40:26Z")

</div>

No worries @thegajan 🙂

Hmm, interesting, I’m not too sure. Can I ask what you have changed from the original tutorial, and what your new device looks like?

---

<div class="post-metadata">

**Author:** ![thegajan](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@thegajan](https://discuss.pennylane.ai/u/thegajan)\
**Post date:** [November 22, 2019, 3:00am UTC](https://discuss.pennylane.ai/t/problem-using-cirq-plugin-as-backend/274/5 "2019-11-22T03:00:02Z")

</div>

@josh only changed the device (from default.qubit to cirq.simulator). Everything else is the same as the demo code.

---

<div class="post-metadata">

**Author:** ![johannesjmeyer](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/johannesjmeyer/32/115_2.png) [@johannesjmeyer](https://discuss.pennylane.ai/u/johannesjmeyer)\
**Post date:** [November 28, 2019, 4:07pm UTC](https://discuss.pennylane.ai/t/problem-using-cirq-plugin-as-backend/274/6 "2019-11-28T16:07:50Z")

</div>

Hi @thegajan, I was mainly responsible for creating the Cirq plugin, but the behaviour you point out is rather confusing because we basically just access Cirq’s internal simulator, so there should no be qualitative difference between `cirq.simulator` and `default.qubit`.

I’ll investigate this and look for some bug that’s hidden somewhere in the pre- and postprocessing and come back to you.

---

<div class="post-metadata">

**Author:** ![johannesjmeyer](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/johannesjmeyer/32/115_2.png) [@johannesjmeyer](https://discuss.pennylane.ai/u/johannesjmeyer)\
**Post date:** [November 29, 2019, 1:02pm UTC](https://discuss.pennylane.ai/t/problem-using-cirq-plugin-as-backend/274/7 "2019-11-29T13:02:40Z")

</div>

So, @thegajan, I found the reason for the bad performance. It is actually no bug in the PennyLane-Cirq plugin, but in the Data-reuploading classifier example.

The example should not use the internal state of the simulator to make predictions, because this is not hardware-friendly. In this special case using the internal state causes an error because the Cirq plugin applies gates under the hood to diagonalize the Hermitian observables with eigenvalues in ascending order. This means that the final state of the simulation is different for the Cirq simulator and the default qubit simulator which causes erroneous predictions and therefore poor performance.

We will work on fixing the Data-reuploading classifier as soon as possible!

---

<div class="post-metadata">

**Author:** ![josh](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/josh/32/100_2.png) [@josh](https://discuss.pennylane.ai/u/josh)\
**Post date:** [January 18, 2020, 6:12pm UTC](https://discuss.pennylane.ai/t/problem-using-cirq-plugin-as-backend/274/8 "2020-01-18T18:12:17Z")

</div>

Hi @thegajan, we’ve now fixed the data re-uploading tutorial, so the latest version should work correctly on the Cirq plugin 🙂

> **[Data-reuploading classifier — PennyLane](https://pennylane.ai/qml/demos/tutorial_data_reuploading_classifier.html)**
>
> Implement a single-qubit universal quantum classifier using PennyLane.
