quantumlib / OpenFermion

The electronic structure package for quantum computers.
Apache License 2.0
1.5k stars 371 forks source link

The ASCII diagarm #604

Closed quantum-rookie closed 3 years ago

quantum-rookie commented 4 years ago

Hi.when i tried to get the ground state of the tunneling term of a FermiHubbard model Hamiltonian in pycharm, The circuit diagrams I got were different from those in the literature(OpenFermion: The Electronic Structure Package for Quantum Computers).What's wrong? image

ncrubin commented 4 years ago

Looks like you are generating a circuit below half filling. The example in the openfermion paper is for half filling. I'd need to see the code you used to generate this plot to help diagnose any potential problem.

quantum-rookie commented 4 years ago

Ok. The following code:

import cirq import openfermion import openfermioncirq as ofc

hubbard_model = openfermion.fermi_hubbard(2, 2, 1.0, 4.0) quad_ham = openfermion.get_quadratic_hamiltonian(hubbard_model, ignore_incompatible_terms=True)

qubits = cirq.LineQubit.range(8) circuit = cirq.Circuit.from_ops( ofc.prepare_gaussian_state(qubits, quad_ham) )

print (circuit.to_text_diagram(transpose=False , use_unicode_characters=False))

quantum-rookie commented 4 years ago

Looks like you are generating a circuit below half filling. The example in the openfermion paper is for half filling. I'd need to see the code you used to generate this plot to help diagnose any potential problem.

so could you tell me how to change the number of electrons in Hubbard model

kevinsung commented 4 years ago

@quantum-rookie You can specify the orbitals to occupy by passing the occupied_orbitals argument. The orbitals are in ascending order by energy, so to fill the lowest energy 4 orbitals (out of 8) you would do

ofc.prepare_gaussian_state(qubits, quad_ham, occupied_orbitals=range(4))

If you want to fill 2 spin-up orbitals and 2 spin-down orbitals, then pass in 2 sequences:

openfermion.prepare_gaussian_state(qubits, quad_ham, occupied_orbitals=[range(2), range(2)])
quantum-rookie commented 4 years ago

image i dont know why. so far so bad. python 3.85 openfermion 0.11.0 openfermioncirq 0.40 cirq0.8.2 @kevinsung

kevinsung commented 3 years ago

Circuit.from_ops was removed in cirq 0.8. Instead of Circuit.from_ops(...), just do Circuit(...). Or downgrade to cirq 0.7.

quantum-rookie commented 3 years ago

ok. i really appreciate your help. thank you!