iqsharp icon indicating copy to clipboard operation
iqsharp copied to clipboard

from qsharp import compile on windows python 3.8

Open cqc-melf opened this issue 4 years ago • 6 comments

Hi qsharp team,

On windows with python 3.8 the import of qsharp fails with the following error message:

from qsharp import compile as qscompile  # type: ignore

C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\site-packages\qsharp_init_.py:198: in client = start_client() C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\site-packages\qsharp\clients_init.py:34: in _start_client client = qsharp.clients.iqsharp.IQSharpClient(kernel_name=kernel_name) E AttributeError: partially initialized module 'qsharp' has no attribute 'clients' (most likely due to a circular import)

The fail occurs on the github ci, if you want to you can take a look on it at:

We tried different qsharp version, for example 0.18.2107.153439 and 0.18.2108.160999. The error occurs in all of them.

https://github.com/CQCL/pytket-extensions/runs/3534918995?check_suite_focus=true

If you need more details, please let me know.

cqc-melf avatar Sep 07 '21 15:09 cqc-melf

Thanks for raising this, @cqc-melf! I'm not able to reproduce locally, would you be willing to share what commands you used to install the qsharp package? Thank you!

cgranade avatar Sep 07 '21 15:09 cgranade

Hi @cgranade, thank you for your fast response! You can find this online in our git repository, it contains two steps:

  1. install iqsharp in https://github.com/CQCL/pytket-extensions/blob/develop/.github/workflows/build_and_test.yml#L123
  2. install qsharp as requirement in the setup of pytket-qsharp, see https://github.com/CQCL/pytket-extensions/blob/develop/modules/pytket-qsharp/setup.py#L43

If you need more details, please let me know.

cqc-melf avatar Sep 07 '21 16:09 cqc-melf

No worries, happy to help! That looks like it should work for installing iqsharp, not sure why I'm getting different behavior than you see in your CI. Let me investigate and get back to you. Thanks for the details!

cgranade avatar Sep 07 '21 16:09 cgranade

This is a minimal github workflow script that reproduces the issue:

name: Build and test
on:
  push:
    branches:
      - debug/qsharpwin
env:
  IQSHARP_TELEMETRY_OPT_OUT: 1
jobs:
  windows:
    name: Build and test (Windows)
    runs-on: windows-2019
    steps:
    - name: Set up Python 3.8
      uses: actions/setup-python@v2
      with:
        python-version: 3.8
    - name: Install dotnet SDK and iqsharp
      run: |
        Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -outfile "dotnet-install.ps1"
        .\dotnet-install.ps1
        dotnet tool install -g Microsoft.Quantum.IQSharp
        pip install jupyter
        dotnet iqsharp install --user
        pip install qsharp
        python -c "import qsharp"

The error occurs with Python 3.8 or 3.9 but not 3.7.

cqc-alec avatar Sep 14 '21 14:09 cqc-alec

The error goes away if I update pyzmq with pip install -U pyzmq after installing qsharp. Unfortunately, this then falls foul of #376 and we get unpredictable hangs.

cqc-alec avatar Sep 16 '21 14:09 cqc-alec

With the latest version of qsharp (0.22.186910), the error is different:

Preparing Q# environment...
Exception ignored in: <function Socket.__del__ at 0x000002C50F701790>
Traceback (most recent call last):
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\site-packages\zmq\sugar\socket.py", line 67, in __del__
    self.close()
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\site-packages\zmq\_future.py", line 160, in close
    self._clear_io_state()
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\site-packages\zmq\asyncio\__init__.py", line 60, in _clear_io_state
    self.io_loop.remove_reader(self._fd)
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\asyncio\events.py", line 504, in remove_reader
    raise NotImplementedError

Still seems related to zmq.

This is with the following github-actions script:

name: Build and test
on:
  push:
    branches:
      - test-qsharp

env:
  IQSHARP_TELEMETRY_OPT_OUT: 1
jobs:
  windows:
    name: Build and test (Windows)
    runs-on: windows-2019
    steps:
    - name: Set up Python 3.8
      uses: actions/setup-python@v2
      with:
        python-version: 3.8
    - name: Install dotnet SDK
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: '3.1.x'
    - name: Install iqsharp
      run: |
        dotnet tool install -g Microsoft.Quantum.IQSharp
        pip install jupyter
        dotnet iqsharp install --user
        pip install -U qsharp
        python -c "import qsharp"

cqc-alec avatar Jan 26 '22 09:01 cqc-alec

Thanks for your report! I believe this should be fixed with #685, but please feel free to re-open if you encounter a regression. Thank you!

cgranade avatar Sep 27 '22 16:09 cgranade