Successfully reported this slideshow.

# quantum chemistry on quantum computer handson by Q# (2019/8/4@MDR Hongo, Tokyo)

Q#を用い、量子化学計算を量子コンピュータシミュレータで行う。ハンズオン資料。2019/8/4@MDR Hongo, Tokyo. 普段省略されがちな量子化学パートを比較的しっかりやります。やっぱり二回に分けたほうが良かったかな。量子コンピュータ部分はQ#に頼りっぱなしですが、量子化学まで来るとかなり高級な記述をしないと難しいかなと思います。いずれにせよ位相推定、量子フーリエ変換しか使ってませんが。

• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

### quantum chemistry on quantum computer handson by Q# (2019/8/4@MDR Hongo, Tokyo)

1. 1. ̂HΨ = EΨ
2. 2. ̂HΨ(r1, ⋯, rN) = EΨ(r1, ⋯, rN) ̂H Ψ E ̂H = − ℏ2 2me ∇2 1 − ℏ2 2me ∇2 2 − e2 4πϵ0 ( 1 ra1 + 1 rb1 + 1 ra2 + 1 rb2 ) + e2 4πϵ0 1 r12 + e2 4πϵ0R Ψ(x1, y1, z1, x2, y2, z2)
3. 3. ̂Hx = λx
4. 4. N 1 N − 1 N − 1 3N 3 N |⟨ΨfullCI |ΨHartree−Fock⟩|2 ≈ 1 1 3N N
5. 5. |Ψ0⟩ {χa}i=1,⋯,r Ψ0⟩ = χ1χ2⋯χa χb⋯χN⟩ E0 = ⟨Ψ0 | ̂ℋ|Ψ0⟩ = ∑ a ⟨a|h|a⟩ + 1 2 ∑ ab ⟨ab||ab⟩ ⟨χa |χb⟩ = δab
6. 6. [ h(1) + N ∑ b=1 𝒥b(1) − 𝒦b(1) ] χa(1) = N ∑ b=1 εba χb(1) f χa⟩ = N ∑ b=1 εba xb⟩ f χa⟩ = εa χa⟩
7. 7. {ϕμ} ψi = K ∑ μ=1 Cμiϕμ Sμv = ∫ dr1ϕ*μ (1)ϕv(1) Fμv = ∫ dr1ϕ*μ (1)f(1)ϕv(1) ∑ v FμvCvi = εi ∑ v SμvCvi FC = SCε
8. 8. FC = SCε Fμv = Hcore μv + ∑ a ∑ λσ CλaC*σa[2(μv|σλ) − (μλ|σv)]
9. 9. \$ sudo apt install psi4 python3-numpy libopenblas-dev …
10. 10. #! STO-3G H2 Hartree-Fock Energy Point # see also: http://pubchemqc.riken.jp/cgi-bin/molecularquery.py?name=hydrogen molecule h2 { H 0.0 0.0 0.0 H 0.0 0.0 1.4 unit bohr } set { basis STO-3G } thisenergy = energy('hf')
11. 11. #! STO-3G H2 Hartree-Fock Energy Point # see also: http://pubchemqc.riken.jp/cgi-bin/molecularquery.py?name=hydrogen molecule h2 { H 0.0 0.0 0.0 H 0.0 0.0 1.4 unit bohr } set { basis STO-3G } thisenergy = energy('hf')
12. 12. **** H 0 S 3 1.00 3.42525091 0.15432897 0.62391373 0.53532814 0.16885540 0.44463454
13. 13. en, wfn = energy('hf', return_wfn=True) nbf = wfn.nso() mints = psi4.core.MintsHelper(wfn.basisset()) S = np.asarray(mints.ao_overlap()) for i in range(nbf): for j in range(nbf): print (i+1,j+1, S[i,j])
14. 14. (μv|λσ)
15. 15. |Ψ0⟩ {χa}i=1,⋯,r |Ψ0⟩ = |χ1χ2⋯χa χb⋯χN⟩ {χa}i=1,⋯,r
16. 16. |Ψ0⟩ |Ψ⟩ = c0 |Φ0⟩ + occ ∑ i vir ∑ a ca i |Φa i ⟩ + occ ∑ i<j vir ∑ a<b cab ij |Φab ij ⟩ + occ ∑ i<j<k vir ∑ a<b<c cabc ijk |Φabc ijk ⟩ + ⋯ |Φ0⟩ |Φ0⟩ = |χ1χ2⋯χa χb⋯χN⟩ |Φa i ⟩ |Φa i ⟩ = |χ1χ2⋯χi−1χa χi+1⋯χN⟩ |Φab ij ⟩ |Φab ij ⟩ = |χ1χ2⋯χi−1χa χi+1⋯χj−1χb χj+1⋯χN⟩ ca i , cab ij
17. 17. |Ψ⟩ = c0 |Φ0⟩ + occ ∑ i vir ∑ a ca i |Φa i ⟩ + occ ∑ i<j vir ∑ a<b cab ij |Φab ij ⟩ + occ ∑ i<j<k vir ∑ a<b<c cabc ijk |Φabc ijk ⟩ + ⋯ min ⟨Ψ|Ψ⟩=1 ⟨Ψ| ̂H|Ψ⟩
18. 18. rCN
19. 19. #! STO-3G H2 FullCI Energy Point # see also: http://pubchemqc.riken.jp/cgi-bin/molecularquery.py?name=hydrogen molecule h2 { H 0.0 0.0 0.0 H 0.0 0.0 1.4 unit bohr } set { basis STO-3G } thisenergy = energy(‘fci')
20. 20. |⟨ΨFullCI |ΦHF⟩|2 = − 0.9872
21. 21. |Ψ⟩ = c0 |Φ0⟩ + occ ∑ i vir ∑ a ca i |Φa i ⟩ + occ ∑ i<j vir ∑ a<b cab ij |Φab ij ⟩ + occ ∑ i<j<k vir ∑ a<b<c cabc ijk |Φabc ijk ⟩ + ⋯ |ΨfullCI⟩ = − 0.993627|ΦHF⟩ + 0.112716|Φ2¯2 1¯1 ⟩ |⟨ΨFullCI |ΦHF⟩|2 = 0.9872
22. 22. |⟨ΨFullCI |ΦHF⟩|2 r(H − H) r(H − H)
23. 23. |⟨ΨFullCI |ΦHF⟩|2
24. 24. (7C5)2 = 21 * 21 = 441
25. 25. : CCSD(T), MP2 14_n2_631g_cc_mp_pes.dat N-N FullCI Hartree-Fock CCSD(T) MP2 fullCI (1.5A ?)
26. 26. |⟨ΨfullCI |ΨHF⟩|2
27. 27. |11⟩, |01⟩, |10⟩, |00⟩ |111⟩, |101⟩, |110⟩, |100⟩ |011⟩, |001⟩, |010⟩, |000⟩ |1⟩, |0⟩ |00000000⟩ + |00000001⟩ + . . . + |11111111⟩
28. 28. ei ̂Ht |ΦHF⟩ = c0eiE0t |Ψ0⟩ + c1eiE1t |Ψ1⟩ + c2eiE2t |Ψ2⟩⋯ ei ̂Hτ ≈ ∏ i eHΔτi ≈ ∏ i e ∑j HjΔτi ̂H|Ψ⟩ = E|Ψ⟩ → ei ̂Hτ |Ψ⟩ = ̂U|Ψ⟩ = ei2πϕ |Ψ⟩ ei2πϕ |Ψ⟩ ⊗ |R⟩ → ei2πϕ |Ψ⟩ ⊗ ei2πϕ |R⟩ → measure|R⟩ → E = 2πϕ/τ
29. 29. |⟨ΦFullCI |ΦHF⟩|2 ≈ 1 E0 ≤ E1 ≤ E2 ≤ ⋯
30. 30. \$ dotnet new -i “Microsoft.Quantum.ProjectTemplates::0.7-*” …
31. 31. \$ mkdir -p qsharp \$ cd qsharp \$ sudo apt install git \$ git clone https://github.com/Microsoft/Quantum.git \$ git clone https://github.com/microsoft/QuantumLibraries
32. 32. |ψ⟩ CNOT(H ⊗ 1)|00⟩ ⟶ |00⟩ + |11⟩ 2
33. 33. |ψ⟩ = α|0⟩ + β|1⟩ |ψ⟩ ⊗ |00⟩ + |11⟩ 2 (H ⊗ 1 ⊗ 1)[CNOT ⊗ 1]|ψ⟩ ⊗ |00⟩ + |11⟩ 2 = 1 2 [α|000⟩ + α|100⟩ + α|011⟩ + α|111⟩ + β|010⟩ − β|110⟩ + β|001⟩ − β|101⟩] 1 2 [|00⟩(α|0⟩ + β|1⟩) + |01⟩(α|1⟩ + β|0⟩) + |10⟩(α|0⟩ − β|1⟩) + |11⟩(α|1⟩ − β|0⟩)]
34. 34. \$ cd Quantum/Samples/src/Teleportation \$ dotnet run Round 0: Sent True, got True. Teleportation successful!! Round 1: Sent False, got False. Teleportation successful!! Round 2: Sent False, got False. Teleportation successful!! Round 3: Sent True, got True. Teleportation successful!! Round 4: Sent False, got False. Teleportation successful!! Round 5: Sent True, got True. Teleportation successful!! Round 6: Sent True, got True. Teleportation successful!! Round 7: Sent False, got False. Teleportation successful!!
35. 35. operation Teleport (msg : Qubit, target : Qubit) : Unit { using (register = Qubit()) { // Create some entanglement that we can use to send our message. H(register); CNOT(register, target); // Encode the message into the entangled pair, // and measure the qubits to extract the classical data // we need to correctly decode the message into the target qubit: CNOT(msg, register); H(msg); let data1 = M(msg); let data2 = M(register); // decode the message by applying the corrections on // the target qubit accordingly: if (data1 == One) { Z(target); } if (data2 == One) { X(target); } // Reset our "register" qubit before releasing it. Reset(register); } }
36. 36. // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. using Microsoft.Quantum.Simulation.Simulators; using System.Linq; namespace Microsoft.Quantum.Samples.Teleportation { class Program { static void Main(string[] args) { using (var sim = new QuantumSimulator()) { var rand = new System.Random(); foreach (var idxRun in Enumerable.Range(0, 8)) { var sent = rand.Next(2) == 0; var received = TeleportClassicalMessage.Run(sim, sent).Result; System.Console.WriteLine(\$"Round {idxRun}:tSent {sent},tgot {received}."); System.Console.WriteLine(sent == received ? "Teleportation successful!!n" : "n"); } } } } }
37. 37. ̂H = ∑ i,j vija† i aj + 1 2 ∑ ijkl wijkla† i a† j alak |Ψ⟩ ̂H|Ψ⟩ = E|Ψ⟩
38. 38. |⟨ΦFullCI |ΦHF⟩|2 ≈ 1 E0 ≤ E1 ≤ E2 ≤ ⋯
39. 39. |Ψ⟩ = c0 |Φ0⟩ + occ ∑ i vir ∑ a ca i |Φa i ⟩ + occ ∑ i<j vir ∑ a<b cab ij |Φab ij ⟩ + occ ∑ i<j<k vir ∑ a<b<c cabc ijk |Φabc ijk ⟩ + ⋯ |Φ0⟩ = |χ1χ2⋯χa χb⋯χN⟩ |Φa i ⟩ = |χ1χ2⋯χi−1χa χi+1⋯χN⟩ |Φab ij ⟩ = |χ1χ2⋯χi−1χa χi+1⋯χj−1χb χj+1⋯χN⟩ = |111111000000⟩ = |111110001000⟩ = |110110001010⟩ 2r r ≃ log(2r )
40. 40. 1/ N! ̂P12Ψ(x1, x2) = ± Ψ(x1, x2)
41. 41. ̂H|Ψ⟩ = E|Ψ⟩ → ei ̂Hτ |Ψ⟩ = ̂U|Ψ⟩ = ei2πϕ |Ψ⟩ ei2πϕ |Ψ⟩ ⊗ |R⟩ → ei2πϕ |Ψ⟩ ⊗ ei2πϕ |R⟩ → measure|R⟩ → E = 2πϕ/τ
42. 42. ̂H = ∑ i,j vija† i aj + 1 2 ∑ ijkl wijkla† i a† j alak ̂H = ∑ ijkl Hijkla† i a† j alak ei ̂Ht |ΦHF⟩ = c0eiE0t |Ψ0⟩ + c1eiE1t |Ψ1⟩ + c2eiE2t |Ψ2⟩⋯ exp(i ̂Ht) Hijkla† i a† j alak ei ̂Ht ≈ ∏ Δt eHΔt ≈ ∏ Δt e ∑ijkl HijklΔt ≈ ∏ Δt,ijkl eHijklΔt
43. 43. |000000111111 >
44. 44. |⟨ΦFullCI |ΦHF⟩|2 ≈ 1 E0 ≤ E1 ≤ E2 ≤ ⋯ ei ̂Ht |ΦHF⟩ = c0eiE0t |Ψ0⟩ + c1eiE1t |Ψ1⟩ + c2eiE2t |Ψ2⟩⋯
45. 45. \$ cd Quantum/Chemistry/MolecularHydrogen \$ dotnet run ----- Print Hamiltonian PP has 4 entries). [1 * 0u 0d, -1.252477495] [1 * 1u 1d, -1.252477495] [1 * 2u 2d, -0.475934275] [1 * 3u 3d, -0.475934275] PQQP has 6 entries). [1 * 0u 1u 1d 0d, 0.674493166] [1 * 0u 2u 2d 0d, 0.482184583] [1 * 1u 3u 3d 1d, 0.482184583] [1 * 1u 2u 2d 1d, 0.663472101] [1 * 0u 3u 3d 0d, 0.663472101] [1 * 2u 3u 3d 2d, 0.69739801] PQRS has 2 entries). [1 * 0u 3u 2d 1d, -0.362575036] [1 * 0u 1u 3d 2d, 0.362575036] Identity has 1 entries). [1 * , 0.713776188] ----- End Print Hamiltonian ----- Creating Jordan–Wigner encoding ----- End Creating Jordan–Wigner encoding ----- Print Hamiltonian Identity has 1 entries). [Identity: [ ], -0.098834446] Z has 4 entries). [Z: [ 0 ], 0.171201285] [Z: [ 1 ], 0.171201285] [Z: [ 2 ], -0.222796536] [Z: [ 3 ], -0.222796536] ZZ has 6 entries). [ZZ: [ 0 1 ], 0.1686232915] [ZZ: [ 0 2 ], 0.12054614575] [ZZ: [ 1 3 ], 0.12054614575] [ZZ: [ 1 2 ], 0.16586802525] [ZZ: [ 0 3 ], 0.16586802525] [ZZ: [ 2 3 ], 0.1743495025] v01234 has 1 entries). [v01234: [ 0 1 2 3 ], 0, -0.0453218795, 0, 0.0453218795] ----- End Print Hamiltonian \$ psi4 07_h2_sto3g_hf_dumpint.dat 1 electron integral 1 1 -1.25247730398 2 2 -0.475934461144 2 electron integral 1 1 1 1 0.674493103326 1 2 1 2 0.181287535812 2 2 1 1 0.663472044861 2 2 2 2 0.69739794982
46. 46. Exact molecular Hydrogen ground state energy: -1.137260278. ----- Performing quantum energy estimation by Trotter simulation algorithm Rep #1/5: Energy estimate: -1.16005261648883; Phase estimate: -0.424487268195532 Rep #2/5: Energy estimate: -1.11126176600452; Phase estimate: -0.404970928001809 Rep #3/5: Energy estimate: -1.14194138176224; Phase estimate: -0.417242774304894 Rep #4/5: Energy estimate: -1.12383014703564; Phase estimate: -0.409998280414257 Rep #5/5: Energy estimate: -1.11126176600452; Phase estimate: -0.404970928001809 ----- End Performing quantum energy estimation by Trotter simulation algorithm ----- Performing quantum energy estimation by Qubitization simulation algorithm Rep #1/1: Energy estimate: -1.1347488350418; Phase estimate: -0.581804128657449 ----- End Performing quantum energy estimation by Qubitization simulation algorithm
47. 47. namespace Microsoft.Quantum.Chemistry.Samples.Hydrogen { class Program { static void Main(string[] args) { ////////////////////////////////////////////////////////////////////////// // Introduction ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // In this example, we will create a spin-orbital representation of the molecular // Hydrogen Hamiltonian `H`, given ovelap coefficients for its one- and // two - electron integrals. // We when perform quantum phase estimation to obtain an estimate of // the molecular Hydrogen ground state energy. #region Building the Hydrogen Hamiltonian through orbital integrals // One of the simplest representations of Hydrogen uses only two // molecular orbitals indexed by `0` and `1`. var nOrbitals = 2; // This representation also has two occupied spin-orbitals. var nElectrons = 2; // The Coulomb repulsion energy between nuclei is var energyOffset = 0.713776188; // One-electron integrals are listed below // <0|H|0> = -1.252477495 // <1|H|1> = -0.475934275 // Two-electron integrals are listed below // <00|H|00> = 0.674493166 // <01|H|01> = 0.181287518 // <01|H|10> = 0.663472101 // <11|H|11> = 0.697398010 • \$ psi4 07_h2_sto3g_hf_dumpint 1 electron integral 1 1 -1.25247730398 2 2 -0.475934461144 2 electron integral 1 1 1 1 0.674493103326 1 2 1 2 0.181287535812 2 2 1 1 0.663472044861 2 2 2 2 0.69739794982
48. 48. // We initialize a fermion Hamiltonian data structure and add terms to it var fermionHamiltonian = new OrbitalIntegralHamiltonian(orbitalIntegrals).ToFermionHamiltonian(); // These orbital integral terms are automatically expanded into // spin-orbitals. We may print the Hamiltonian to see verify what it contains. Console.WriteLine("----- Print Hamiltonian"); Console.Write(fermionHamiltonian); Console.WriteLine("----- End Print Hamiltonian n"); // We also need to create an input quantum state to this Hamiltonian. // Let us use the Hartree–Fock state. var fermionWavefunction = fermionHamiltonian.CreateHartreeFockState(nElectrons); #endregion #region Jordan–Wigner representation // The Jordan–Wigner encoding converts the fermion Hamiltonian, // expressed in terms of Fermionic operators, to a qubit Hamiltonian, // expressed in terms of Pauli matrices. This is an essential step // for simulating our constructed Hamiltonians on a qubit quantum // computer. Console.WriteLine("----- Creating Jordan–Wigner encoding"); var jordanWignerEncoding = fermionHamiltonian.ToPauliHamiltonian(Paulis.QubitEncoding.JordanWigner); Console.WriteLine("----- End Creating Jordan–Wigner encoding n"); // Print the Jordan–Wigner encoded Hamiltonian to see verify what it contains. Console.WriteLine("----- Print Hamiltonian"); Console.Write(jordanWignerEncoding); Console.WriteLine("----- End Print Hamiltonian n"); #endregion