Skip to content

Commit

Permalink
Initial outline of paper2 circuit ansatz
Browse files Browse the repository at this point in the history
  • Loading branch information
chmwzc committed May 16, 2024
1 parent 812e327 commit 6b9862e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
10 changes: 6 additions & 4 deletions examples/psr_paper2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
from qibo.optimizers import optimize
from scipy.optimize import minimize

from qibochem.ansatz.hf_reference import hf_circuit
from qibochem.ansatz.ucc import ucc_circuit
from qibochem.driver.molecule import Molecule
from qibochem.measurement.expectation import expectation
from qibochem.ansatz import hf_circuit, ucc_circuit
from qibochem.driver import Molecule
from qibochem.measurement import expectation

# mol = Molecule(xyz_file="h2.xyz")
h2 = Molecule([("Li", (0.0, 0.0, 0.0)), ("H", (0.0, 0.0, 1.4))])
Expand Down Expand Up @@ -75,6 +74,9 @@ def A_gate(a):
Xpositions += [2 * j + 1 for j in range(h2.n_active_e - math.ceil(h2.n_active_orbs / 2))]
Xpositions.sort()

print(Xpositions)
quit()


# setting the circuit up
def setup_electrons(g2):
Expand Down
52 changes: 52 additions & 0 deletions src/qibochem/ansatz/symmetry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
Symmetry-Preserving circuit ansatz from Gard et al. Reference: https://doi.org/10.1038/s41534-019-0240-1
"""

import numpy as np
from qibo import Circuit, gates

Check warning on line 6 in src/qibochem/ansatz/symmetry.py

View check run for this annotation

Codecov / codecov/patch

src/qibochem/ansatz/symmetry.py#L5-L6

Added lines #L5 - L6 were not covered by tests

# Helper functions


def a_gate(qubit1, qubit2):

Check warning on line 11 in src/qibochem/ansatz/symmetry.py

View check run for this annotation

Codecov / codecov/patch

src/qibochem/ansatz/symmetry.py#L11

Added line #L11 was not covered by tests
"""
Returns the list of elementary gates corresponding to the 'A' gate as defined in the paper, acting on qubit1 and qubit2
"""
result = []
result.append(gates.CNOT(qubit2, qubit1))
result += [gates.RY(qubit2, 0.0), gates.RZ(qubit2, 0.0)]
result.append(gates.CNOT(qubit1, qubit2))
result += [gates.RZ(qubit2, 0.0), gates.RY(qubit2, 0.0)]
result.append(gates.CNOT(qubit2, qubit1))
return result

Check warning on line 21 in src/qibochem/ansatz/symmetry.py

View check run for this annotation

Codecov / codecov/patch

src/qibochem/ansatz/symmetry.py#L15-L21

Added lines #L15 - L21 were not covered by tests


# Main function
def symm_preserving_circuit(n_qubits, n_electrons):

Check warning on line 25 in src/qibochem/ansatz/symmetry.py

View check run for this annotation

Codecov / codecov/patch

src/qibochem/ansatz/symmetry.py#L25

Added line #L25 was not covered by tests
"""
Symmetry-preserving circuit ansatz
Args:
n_qubits: Number of qubits in the quantum circuit
n_electrons: Number of electrons in the molecular system
Returns:
Qibo ``Circuit``: Circuit ansatz
"""
circuit = Circuit(n_qubits)
circuit.add(gates.X(2 * _i) for _i in range(n_electrons))

Check warning on line 37 in src/qibochem/ansatz/symmetry.py

View check run for this annotation

Codecov / codecov/patch

src/qibochem/ansatz/symmetry.py#L36-L37

Added lines #L36 - L37 were not covered by tests

a_gate_qubits = [] # Generate the list of qubits pairs for adding A gates

Check warning on line 39 in src/qibochem/ansatz/symmetry.py

View check run for this annotation

Codecov / codecov/patch

src/qibochem/ansatz/symmetry.py#L39

Added line #L39 was not covered by tests

a_gate_qubits = [(0, 1)]

Check warning on line 41 in src/qibochem/ansatz/symmetry.py

View check run for this annotation

Codecov / codecov/patch

src/qibochem/ansatz/symmetry.py#L41

Added line #L41 was not covered by tests

a_gates = [a_gate(qubit1, qubit2) for qubit1, qubit2 in a_gate_qubits]
circuit.add(_gates for _a_gate in a_gates for _gates in _a_gate) # Unpack the nested list

Check warning on line 44 in src/qibochem/ansatz/symmetry.py

View check run for this annotation

Codecov / codecov/patch

src/qibochem/ansatz/symmetry.py#L43-L44

Added lines #L43 - L44 were not covered by tests

return circuit

Check warning on line 46 in src/qibochem/ansatz/symmetry.py

View check run for this annotation

Codecov / codecov/patch

src/qibochem/ansatz/symmetry.py#L46

Added line #L46 was not covered by tests


n_qubits = 4
n_electrons = 2
circuit = symm_preserving_circuit(n_qubits, n_electrons)
print(circuit.draw())

Check warning on line 52 in src/qibochem/ansatz/symmetry.py

View check run for this annotation

Codecov / codecov/patch

src/qibochem/ansatz/symmetry.py#L49-L52

Added lines #L49 - L52 were not covered by tests

0 comments on commit 6b9862e

Please sign in to comment.