# Question on creating an MPO

**URL:** <https://itensor.discourse.group/t/question-on-creating-an-mpo/1519>\
**Category:** ITensor Julia Questions\
**Tags:** julia, mpo\
**Created:** [March 4, 2024, 2:02pm UTC](https://itensor.discourse.group/t/question-on-creating-an-mpo/1519 "2024-03-04T14:02:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackennehy1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jackennehy1](https://itensor.discourse.group/u/jackennehy1)\
**Post date:** [March 4, 2024, 2:02pm UTC](https://itensor.discourse.group/t/question-on-creating-an-mpo/1519/1 "2024-03-04T14:02:23Z")

</div>

Hello, I’m looking to simulate Grovers algorithm and investigate the scaling of the bond dimension with number of qubits. My first hurdle is the controlled not gate (CNOT) which acts on an arbitrary number of qubits. My first question - is it at all possible to represent this as an MPO? And if so, how could I go about implementing it in ITensor (I’m fairly new to ITensor). Thank you!

---

<div class="post-metadata">

**Author:** ![eugescu](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/eugescu/32/415_2.png) [@eugescu](https://itensor.discourse.group/u/eugescu)\
**Post date:** [March 5, 2024, 9:23pm UTC](https://itensor.discourse.group/t/question-on-creating-an-mpo/1519/2 "2024-03-05T21:23:02Z")

</div>

Do you want to construct the diffusion and reflection operators? (They look like qubit operators with respect to the target state and the manifold that is the target state’s complement.) If so they are generally big, many-body, operators that will be hard to _ **efficiently** _ factorize in a tensor network or MPO manner unless there is additional structure to leverage which is specific to your example.

I can imagine thinking about the projector onto the target state as an outer product of an MPS but you’ll have to subtract it from the identity operator and that would subsequently be hard to box into a nice tensor.

This question has been studied a bit in [https://arxiv.org/pdf/2303.11317.pdf](https://arxiv.org/pdf/2303.11317.pdf) where the authors show many great intermediate-bond dimension operators are out there for search purposes. I think the message got a bit lost due to the title and Aaronson’ good meaning but overly intense analysis [Shtetl-Optimized » Blog Archive » Xavier Waintal responds (tl;dr Grover is still quadratically faster)](https://scottaaronson.blog/?p=7157)

---

<div class="post-metadata">

**Author:** ![kevinkawchak](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/kevinkawchak/32/486_2.png) [@kevinkawchak](https://itensor.discourse.group/u/kevinkawchak)\
**Post date:** [March 14, 2024, 12:38am UTC](https://itensor.discourse.group/t/question-on-creating-an-mpo/1519/3 "2024-03-14T00:38:13Z")

</div>

Thank you for sharing

---

<div class="post-metadata">

**Author:** ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)\
**Post date:** [March 19, 2024, 6:27pm UTC](https://itensor.discourse.group/t/question-on-creating-an-mpo/1519/4 "2024-03-19T18:27:27Z")

</div>

A very convenient way to make a controlled gate like CNOT as an MPO using ITensor is to use our “OpSum” system. Here’s an example:

```julia
  n = 10 # 10 qubits, no problem to do more
  s = siteinds("Qubit",n)
  i = 3 # i will be the "control" site
  j = 7 # j will be the site where the gate acts 

  cnot = OpSum()
  cnot += "Proj0",i,"Id",j
  cnot += "Proj1",i,"X",j
  CNOT = MPO(cnot,s)

```

The above is using the following way of writing the CNOT gate:

CNOT\_{i,j} = \ket{0}\_i \bra{0}\_i \otimes I\_j + \ket{1}\_i \bra{1}\_i \otimes X\_j

and the fact that the Pauli X operator is identical to the NOT single-qubit gate.
