CQCL / lambeq

A high-level Python library for Quantum Natural Language Processing
https://cqcl.github.io/lambeq-docs
Apache License 2.0
451 stars 108 forks source link

Numpy int32 error #12

Closed ACE07-Sev closed 2 years ago

ACE07-Sev commented 2 years ago

Hi I ran the Quantum_trainer, and been getting this and can't seem to find where the issue is.

Traceback (most recent call last): File "C:\Users\elmm\Desktop\CQM\QNLP Depression.py", line 103, in trainer.fit(train_dataset, val_dataset, logging_step=12) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\trainer.py", line 365, in fit y_hat, loss = self.training_step(batch) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\quantum_trainer.py", line 149, in training_step y_hat, loss = self.optimizer.backward(batch) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\spsa_optimizer.py", line 125, in backward y0 = self.model(diagrams) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\model.py", line 59, in call return self.forward(*args, **kwds) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\tket_model.py", line 131, in forward return self.get_diagram_output(x) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\tket_model.py", line 103, in get_diagram_output seed=self._randint() File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\tket_model.py", line 71, in _randint return np.random.randint(low, high) File "mtrand.pyx", line 746, in numpy.random.mtrand.RandomState.randint File "_bounded_integers.pyx", line 1334, in numpy.random._bounded_integers._rand_int32 ValueError: low is out of bounds for int32

Thommy257 commented 2 years ago

Sorry, we are aware of the issue and it will be fixed in the next minor release. In the meantime, you can change the _randint() (line71-72) method in "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\training\tket_model.py" to the following:

def _randint(self, low=-1 << 63, high=(1 << 63)-1):
    return np.random.randint(low, high, dtype=np.int64)
ACE07-Sev commented 2 years ago

Thank you so much. Right now it is running (it's a bit slow so it's on epoch 120, and has to reach 1000), but I think this fixed the issue.

Thommy257 commented 2 years ago

This is to be expected for the TketModel. To debug your architecture we suggest to use the NumpyModel with jit support enabled (faster by an order of magnitude).

dimkart commented 2 years ago

Sorry, we are aware of the issue and it will be fixed in the next minor release.

@ACE07-Sev Note that the new release is now out, including a fix for this.