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

google module of cirq has been moved to a separate module #307

Closed
dariavh opened this issue Sep 24, 2023 · 3 comments
Closed

google module of cirq has been moved to a separate module #307

dariavh opened this issue Sep 24, 2023 · 3 comments

Comments

@dariavh
Copy link
Contributor

dariavh commented Sep 24, 2023

Describe the bug
When trying to use the sycamore device for simulating my wavefunction, I get the error AttributeError: module 'cirq' has no attribute 'google' because the cirq.google module has been moved into its own module cirq_google.

To Reproduce
Steps to reproduce the behavior:

import tequila as tq

H = tq.paulis.X(0)

wfn = tq.simulate(H, samples=100, device="sycamore", backend="cirq")

Computer (please complete the following information):

  • OS: Linux Darwin Kernel Version 22.3.0
  • Version: Python 3.7.12, tequila 1.8.9

Additional context
I think the bugfix would consist of renaming all cirq.google references to cirq_google (need to check thoroughly) and adding the cirq_google package to the optional backends list in the requirements.txt. I can provide this in a new PR if you want?

@kottmanj
Copy link
Collaborator

That would be amazing!

What would be great to add a small test alongside (in tests/test_simulator_backends.py). E.g.

import importlib
HAS_GOOGLE = importlib.util.find_spec('cirq_google')
@pytest.mark.skipif(condition=HAS_GOOGLE, reason="cirq_google not installed")
def test_cirq_google_devices():
    some tests

and in the same way, including the HAS_GOOGLE in src/tequila/simulators/simulator_cirq.py in order to throw a meaningful error message if someone tries to use the devides that need the cirq_google package installed.

@dariavh
Copy link
Contributor Author

dariavh commented Sep 25, 2023

Hi Jakob,

It seems that a lot has changed in the cirq package over the last years. The Foxtail and Bristlecone devices are deprecated, see 0.14.0 release for the full list. The optimized_for_sycamore() method is deprecated as well and is replaced by optimize_for_target_gateset() that can e.g. optimize an abstract circuit in cirq to gates that are compatible on the Google Sycamore devices.

I am currently working out the details, but I would refactor the build_device_circuit method in simulator_cirq.py as:

if isinstance(device, cirq.Device):
       if device in [cirq_google.Sycamore, cirq_google.Sycamore23]:
             try:
                  circuit = cirq.optimize_for_target_gateset(circuit=c, gateset=cirq_google.SycamoreTargetGateset())
             except ValueError:
                  raise TequilaCirqException('could not optimize for device={}'.format(device))
       else:
             ### under construction (potentially on other branches)
             raise TequilaException('Only Sycamore and Sycamore23 devices currently functional. Sorry!')

@kottmanj
Copy link
Collaborator

Looks good to me!

would suggest the following error handling, then the original Exception from cirq is also displayed (often useful)

             except ValueError as E:
                  original_message = str(E)
                  raise TequilaCirqException('original message:\n{}\n\ncould not optimize for device={}'.format(original_message,device))

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

No branches or pull requests

2 participants