# State preparation with pennylane

**URL:** <https://discuss.pennylane.ai/t/state-preparation-with-pennylane/218>\
**Category:** PennyLane Help\
**Created:** [September 17, 2019, 11:45am UTC](https://discuss.pennylane.ai/t/state-preparation-with-pennylane/218 "2019-09-17T11:45:34Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [September 18, 2019, 8:11pm UTC](https://discuss.pennylane.ai/t/state-preparation-with-pennylane/218/3 "2019-09-18T20:11:20Z")

</div>

In addition, you can also check out the following post for some example code:

> [@Optimizing state overlap / multi-qubit qml.expval.Hermitian()](http://discuss.pennylane.ai/t/optimizing-state-overlap-multi-qubit-qml-expval-hermitian/84/3):
>
> And just for completeness, here is the full optimization: import pennylane as qml from pennylane import numpy as np dev = qml.device('default.qubit', wires=2) @qml.qnode(dev) def circuit(x, target\_observable=None): qml.RX(x[0], wires=0) qml.RY(x[1], wires=0) qml.RZ(x[2], wires=0) qml.CNOT(wires=[0, 1]) return qml.expval.Hermitian(target\_observable, wires=[0, 1]) target\_state = 1/np.sqrt(2) \* np.array([1,0,0,1]) target\_herm\_op = np.outer(target\_state.conj(), target\_state) …

---

_[View the full topic](https://discuss.pennylane.ai/t/state-preparation-with-pennylane/218)._
