From 2627685f563cc31d8a047fb4583c4626f4725483 Mon Sep 17 00:00:00 2001 From: Evgenii Zheltonozhskii Date: Sun, 5 Dec 2021 14:38:15 +0200 Subject: [PATCH] Initial implementation of Pennylane example with JW --- qmlcourseRU/book/problems2qml/jordanwigner.md | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/qmlcourseRU/book/problems2qml/jordanwigner.md b/qmlcourseRU/book/problems2qml/jordanwigner.md index 23b624c8b9..52676550d7 100644 --- a/qmlcourseRU/book/problems2qml/jordanwigner.md +++ b/qmlcourseRU/book/problems2qml/jordanwigner.md @@ -237,3 +237,61 @@ $$ H_k -t\sum_{j}(\sigma^x_{2j}\sigma^x_{2j+2}+ \sigma^y_{2j}\sigma^y_{2j+2}) \sigma^z_{2j} \sigma^z_ {2j+1} + \frac{U}{4} \sum_{j} (1 - \sigma^z_{2j} )(1 - \sigma^z_{2j+1}) $$ + +### Пример. Молекула воды + +```{code-cell} ipython3 +symbols, coordinates = qchem.read_structure('h2o.xyz') +hf_file = qchem.meanfield( + symbols, + coordinates, + name='water', + charge=-1, + mult=2, + basis='6-31g', + package='pyscf' +) +``` +```{code-cell} ipython3 +from openfermion import MolecularData +water = MolecularData(filename=hf_file) +core, active = qchem.active_space( + water.n_electrons, + water.n_orbitals, + mult=2, + active_electrons=3, + active_orbitals=4 +) +``` +```{code-cell} ipython3 +qubit_hamiltonian = qchem.decompose( + hf_file, + mapping='jordan_wigner', + core=core, + active=active +) +``` + + + +```{code-cell} ipython3 +import pennylane as qml + +dev = qml.device('default.qubit', wires=4) + +hamiltonian = 2.0 * qml.PauliZ(0) @ qml.PauliZ(1) + +@qml.qnode(dev) +def circuit(params): + qml.BasisState(np.array([1, 1, 0, 0]), wires=[0,1,2,3]) + for i in range(4): + qml.Rot(*params[i], wires=i) + qml.CNOT(wires=[2, 3]) + qml.CNOT(wires=[2, 0]) + qml.CNOT(wires=[3, 1]) + return qml.expval(hamiltonian) + +rng = np.random.default_rng(seed=42) +params = rng.random([4, 3]) +circuit(params) +``` \ No newline at end of file