mit-han-lab / torchquantum

A PyTorch-based framework for Quantum Classical Simulation, Quantum Machine Learning, Quantum Neural Networks, Parameterized Quantum Circuits with support for easy deployments on real quantum computers.
https://torchquantum.org
MIT License
1.3k stars 197 forks source link

ModuleNotFoundError: No module named 'torchquantum.plugin' #219

Closed bsiegelwax closed 8 months ago

bsiegelwax commented 9 months ago

Running the "Basic Usage" example results in:

class: QuantumDevice 
 device name: default 
 number of qubits: 2 
 batch size: 5 
 current computing device: cpu 
 recording op history: True 
 current states: [[ 0.48445618+0.12370197j  0.48445618-0.12370197j -0.48445618-0.12370197j
   0.48445618-0.12370197j]
 [ 0.48445618+0.12370197j  0.48445618-0.12370197j -0.48445618-0.12370197j
   0.48445618-0.12370197j]
 [ 0.48445618+0.12370197j  0.48445618-0.12370197j -0.48445618-0.12370197j
   0.48445618-0.12370197j]
 [ 0.48445618+0.12370197j  0.48445618-0.12370197j -0.48445618-0.12370197j
   0.48445618-0.12370197j]
 [ 0.48445618+0.12370197j  0.48445618-0.12370197j -0.48445618-0.12370197j
   0.48445618-0.12370197j]]
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
[<ipython-input-12-9273634550b9>](https://localhost:8080/#) in <cell line: 22>()
     20 
     21 # obtain the qasm string
---> 22 from torchquantum.plugin import op_history2qasm
     23 print(op_history2qasm(qdev.n_wires, qdev.op_history))
     24 

ModuleNotFoundError: No module named 'torchquantum.plugin'

in Google Colab.

GenericP3rson commented 9 months ago

Hi! Thanks for opening the issue. The Basic Usage sample code is working on my end. How are you installing TQ? I think the issues should be resolved if you install from source:

!git clone https://github.com/mit-han-lab/torchquantum.git
!cd torchquantum && pip install --editable .

Let me know if this works and if you have any further questions! I’ll also see about getting the pip version updated.

bsiegelwax commented 9 months ago

I'm trying it in Google Colab. I have a blanket policy against installing anything locally.

GenericP3rson commented 9 months ago

To clarify, you should be able to copy and paste the snippet from my previous comment into a Colab cell to make the Basic Usage code work in Colab.

bsiegelwax commented 9 months ago

That changed the error to:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
[<ipython-input-27-9273634550b9>](https://localhost:8080/#) in <cell line: 2>()
      1 import torchquantum as tq
----> 2 import torchquantum.functional as tqf
      3 
      4 qdev = tq.QuantumDevice(n_wires=2, bsz=5, device="cpu", record_op=True) # use device='cuda' for GPU
      5 

ModuleNotFoundError: No module named 'torchquantum.functional'
GenericP3rson commented 9 months ago

Try this Colab notebook: https://colab.research.google.com/drive/17E-QMAW0cAjI4HGiAQ7mS5wloqbjmwJF?usp=sharing

GenericP3rson commented 9 months ago

My guess is maybe the error is related to the old TQ still being installed. The above Colab worked just fine for me, but let me know if there are any errors on your side!

GenericP3rson commented 8 months ago

Marking as resolved for now but please let me know if you have any more questions!

badreddinemerabet commented 6 months ago

ModuleNotFoundError Traceback (most recent call last) in <cell line: 2>() 1 import torchquantum as tq ----> 2 import torchquantum.functional as tqf 3 4 qdev = tq.QuantumDevice(n_wires=2, bsz=5, device="cpu", record_op=True) # use device='cuda' for GPU 5

ModuleNotFoundError: No module named 'torchquantum.functional'

I have the error also, and I didn't manage to solve it

Also I tried the colab notebook u post