# How to output the unitary matrix for a given quantum circuit using pennylane?

**URL:** <https://discuss.pennylane.ai/t/how-to-output-the-unitary-matrix-for-a-given-quantum-circuit-using-pennylane/1409>\
**Category:** PennyLane Help\
**Created:** [October 13, 2021, 2:31pm UTC](https://discuss.pennylane.ai/t/how-to-output-the-unitary-matrix-for-a-given-quantum-circuit-using-pennylane/1409 "2021-10-13T14:31:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyrie\_wang](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/cyrie_wang/32/742_2.png) [@cyrie\_wang](https://discuss.pennylane.ai/u/cyrie_wang)\
**Post date:** [October 13, 2021, 2:31pm UTC](https://discuss.pennylane.ai/t/how-to-output-the-unitary-matrix-for-a-given-quantum-circuit-using-pennylane/1409/1 "2021-10-13T14:31:31Z")

</div>

The problem is described in the title. I am trying to obtain a unitary matrix for a specific quantum circuit using pennylane, but I can’t find the available qml. function to get it. Thanks for the help!

---

<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:** [October 13, 2021, 4:01pm UTC](https://discuss.pennylane.ai/t/how-to-output-the-unitary-matrix-for-a-given-quantum-circuit-using-pennylane/1409/2 "2021-10-13T16:01:52Z")

</div>

Hi @cyrie_wang! If you are using the latest GitHub version of PennyLane, installable using

```auto
pip install git+https://github.com/PennyLaneAI/pennylane.git#egg=pennylane

```

then you can access the new [`qml.transforms.get_unitary_matrix()`](https://pennylane.readthedocs.io/en/latest/code/api/pennylane.transforms.get_unitary_matrix.html) function:

```python
def circuit(theta):
    qml.RX(theta, wires=1)
    qml.PauliZ(wires=0)

```

We can use `get_unitary_matrix()` to generate a new function that returns the unitary matrix corresponding to the function circuit:

```auto
>>> get_matrix = get_unitary_matrix(circuit)
>>> theta = np.pi/4
>>> get_matrix(theta)

```

---

<div class="post-metadata">

**Author:** ![cyrie\_wang](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/cyrie_wang/32/742_2.png) [@cyrie\_wang](https://discuss.pennylane.ai/u/cyrie_wang)\
**Post date:** [October 17, 2021, 2:43pm UTC](https://discuss.pennylane.ai/t/how-to-output-the-unitary-matrix-for-a-given-quantum-circuit-using-pennylane/1409/3 "2021-10-17T14:43:59Z")

</div>

> [@josh](#):
>
> pip install git+https://github.com/PennyLaneAI/pennylane.git#egg=pennylane

wonderful! thank you so much.

---

<div class="post-metadata">

**Author:** ![alicewithoutbob](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/alicewithoutbob/32/1376_2.png) [@alicewithoutbob](https://discuss.pennylane.ai/u/alicewithoutbob)\
**Post date:** [July 18, 2022, 7:14am UTC](https://discuss.pennylane.ai/t/how-to-output-the-unitary-matrix-for-a-given-quantum-circuit-using-pennylane/1409/4 "2022-07-18T07:14:25Z")

</div>

Hi All,

I just wanted to give a quick update on this topic as it is still well referenced in search engines, and I spent some time trying to find the answer myself.  
Since Release 0.23.0 (see [release notes](https://pennylane.readthedocs.io/en/stable/development/release_notes.html)) `qml.transforms.get_unitary_matrix` has been deprecated and the new function to call is `qml.matrix` you can find the doc [here](https://pennylane.readthedocs.io/en/stable/code/api/pennylane.matrix.html)

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [July 18, 2022, 9:36pm UTC](https://discuss.pennylane.ai/t/how-to-output-the-unitary-matrix-for-a-given-quantum-circuit-using-pennylane/1409/5 "2022-07-18T21:36:23Z")

</div>

Thank you so much for posting this here @alicewithoutbob!
