Variational Quantum Eigen Solver

using Yao, Yao.AD, YaoExtensions

number of qubits

n = 4
4

depth

d = 5
circuit = dispatch!(variational_circuit(n, d),:random)

gatecount(circuit)

nparameters(circuit)

h = heisenberg(n)
nqubits: 4
+
├─ +
│  ├─ chain
│  │  ├─ put on (2)
│  │  │  └─ X gate
│  │  └─ put on (1)
│  │     └─ X gate
│  ├─ chain
│  │  ├─ put on (2)
│  │  │  └─ Y gate
│  │  └─ put on (1)
│  │     └─ Y gate
│  └─ chain
│     ├─ put on (2)
│     │  └─ Z gate
│     └─ put on (1)
│        └─ Z gate
├─ +
│  ├─ chain
│  │  ├─ put on (3)
│  │  │  └─ X gate
│  │  └─ put on (2)
│  │     └─ X gate
│  ├─ chain
│  │  ├─ put on (3)
│  │  │  └─ Y gate
│  │  └─ put on (2)
│  │     └─ Y gate
│  └─ chain
│     ├─ put on (3)
│     │  └─ Z gate
│     └─ put on (2)
│        └─ Z gate
├─ +
│  ├─ chain
│  │  ├─ put on (4)
│  │  │  └─ X gate
│  │  └─ put on (3)
│  │     └─ X gate
│  ├─ chain
│  │  ├─ put on (4)
│  │  │  └─ Y gate
│  │  └─ put on (3)
│  │     └─ Y gate
│  └─ chain
│     ├─ put on (4)
│     │  └─ Z gate
│     └─ put on (3)
│        └─ Z gate
└─ +
   ├─ chain
   │  ├─ put on (1)
   │  │  └─ X gate
   │  └─ put on (4)
   │     └─ X gate
   ├─ chain
   │  ├─ put on (1)
   │  │  └─ Y gate
   │  └─ put on (4)
   │     └─ Y gate
   └─ chain
      ├─ put on (1)
      │  └─ Z gate
      └─ put on (4)
         └─ Z gate

pick the one you like either reverse-mode or forward mode grad = faithfulgrad(h, zerostate(n) => circuit; nshots=100)

for i in 1:1000
      _, grad = expect'(h, zero_state(n) => circuit)
      dispatch!(-, circuit, 1e-2 * grad)
      println("Step $i, energy = $(real.(expect(h, zero_state(n)=>circuit)))")
end

using LinearAlgebra
w, _ = eigen(Matrix(mat(h)))

This page was generated using Literate.jl.