Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ffsim simulator backend #90

Merged
merged 33 commits into from Jan 31, 2024
Merged

Conversation

kevinsung
Copy link
Contributor

@kevinsung kevinsung commented Jan 2, 2024

Summary

Adds a simulator backend based on ffsim. For supported circuits, the simulator is orders of magnitude faster than the existing FermionSimulator backend. I made the ffsim dependency optional because it is not supported on Windows.

Benchmark results

I wrote some benchmarks and ran them using asv, but then removed them in 2b7a1a1 so they wouldn't be included in this PR (I can add them back if desired). Using my laptop, I tried running benchmarks at system sizes of up to 16 spatial orbitals at half filling, setting a time limit of 10,000 seconds.

One benchmark used the Hop, Interaction, and Phase gates, which ffsim has special functions for. ffsim completed the simulations for all system sizes, while FermionSimulator failed at 8 orbitals, half filling. At that size, ffsim was at least 400,000 times faster. The speedup is probably greater at larger system sizes.

FermionSimulator:

             --         filling_fraction   
             ------ -----------------------
              norb      0.25        0.5    
             ====== ============ ==========
               4      181±10ms    376±20ms 
               8     1.08±0.02m    failed  
               12       n/a         n/a    
               16       n/a         n/a    
             ====== ============ ==========
             For parameters: 8, 0.5
             
             
             asv: benchmark timed out (timeout 10000s)

ffsim:

             --          filling_fraction     
             ------ --------------------------
              norb      0.25          0.5     
             ====== ============ =============
               4     18.2±0.4ms    17.7±0.4ms 
               8     20.3±0.2ms   22.3±0.08ms 
               12    49.4±0.4ms     816±3ms   
               16     4.14±0s      6.25±0.05m 
             ====== ============ =============

Another benchmark used the FermiHubbard gate, which requires exponentiating a fermionic generator. Here, ffsim failed at 16 orbitals, half filling, and FermionSimulator again failed at 8 orbitals, half filling. At that size, ffsim was at least 750 times faster. There's an open issue at ffsim which, if resolved, would significantly improve its efficiency for this benchmark.

FermionSimulator:

             --        filling_fraction   
             ------ ----------------------
              norb      0.25        0.5   
             ====== ============ =========
               4     82.1±0.9ms   166±2ms 
               8     1.10±0.01m    failed 
               12       n/a         n/a   
               16       n/a         n/a   
             ====== ============ =========
             For parameters: 8, 0.5
             
             
             asv: benchmark timed out (timeout 10000s)

ffsim:

              --          filling_fraction    
              ------ -------------------------
               norb      0.25         0.5     
              ====== ============ ============
                4     1.22±0.04s   1.68±0.1s  
                8     5.26±0.06s   13.2±0.04s 
                12    1.02±0.06m   19.0±0.6m  
                16     1.29±0h       failed   
              ====== ============ ============

@kevinsung kevinsung marked this pull request as draft January 2, 2024 21:51
@kevinsung kevinsung marked this pull request as ready for review January 2, 2024 23:12
@fretchen fretchen self-requested a review January 3, 2024 17:29
@fretchen
Copy link
Collaborator

fretchen commented Jan 3, 2024

@kevinsung this looks really interesting, but it would seem that you are still working on it? Just tell me when it is ready for review.

@kevinsung
Copy link
Contributor Author

@fretchen it's ready for review.

.github/workflows/main.yml Outdated Show resolved Hide resolved
"coupling_map": None,
"description": "ffsim simulator for fermionic circuits. Instead of qubits, each wire represents"
" a single fermionic mode",
"supported_instructions": None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to add here the gates that are allowed in terms of strings. This makes it accessible to the user via backend.configuration().supported_instructions. Then it is also clear that the X,Y,Z gate are not allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this from the other simulator backend. I'm not sure what it should be set to because arbitrary FermionicGates are supported, but those don't have a name. I also noticed that other simulators, like in Qiskit Aer, don't set this property. Perhaps we should just leave it as is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I added supported for the FR{X,Y,Z}Gates.

Copy link
Collaborator

@fretchen fretchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really interesting and looks like something that will be certainly very interesting to users. Thx. However, I have few comments:

  • A simple pip install of ffsim failed as I did not yet have rust cargo. So I would recommend a short section in the README.md on installation with ffsim
  • Do we agree that it would be nice to make this a standard dependency once the windows install works ?
  • So this should be mentioned in the readme as a bit special
  • I had a number of questions concerning the notebook. Most importantly, it would be nice to make it clearer what you are simulating there and what is going on. I will add a commented notebook at the suited place.
  • Could you say a bit more about the occupation etc that you are setting up ?
  • We once again need a Reno file (could contain most of the description of the PR).

I added the other comments directly at the specific parts in the code.

@eggerdj
Copy link
Collaborator

eggerdj commented Jan 4, 2024

Regarding Do we agree that it would be nice to make this a standard dependency once the windows install works ? I agree with that exact statement. However, it might never happen. The reason is (and I might be wrong here) ffsim requires pyscf which to my understanding does not support Windows (and does not intend to[?]). Therefore, we cannot make ffsim a requirement because otherwise windows users will not be able to install qiskit-cold-atom.

@kevinsung kevinsung changed the title Add ffsim simulator backend [After #93] Add ffsim simulator backend Jan 5, 2024
@kevinsung kevinsung changed the title [After #93] Add ffsim simulator backend Add ffsim simulator backend Jan 6, 2024
@kevinsung kevinsung marked this pull request as draft January 8, 2024 01:55
@kevinsung
Copy link
Contributor Author

kevinsung commented Jan 8, 2024

Do we agree that it would be nice to make this a standard dependency once the windows install works ?

What Daniel said is correct. ffsim can't support Windows because it depends on pySCF, which doesn't support Windows.

@kevinsung kevinsung marked this pull request as ready for review January 11, 2024 03:09
@kevinsung
Copy link
Contributor Author

@fretchen As we discussed, I have merged my notebook into the existing introduction notebook and also added the notebook you made via pull request. Please take another look at this PR.

@fretchen fretchen merged commit e4f0993 into qiskit-community:main Jan 31, 2024
13 checks passed
@kevinsung kevinsung deleted the ffsim branch January 31, 2024 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants