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

Issue when running the quantum training example #10

Closed RoshniRM closed 2 years ago

RoshniRM commented 2 years ago

Hi ,

Ran into an issue when running the quantum trainer : "ValueError: low is out of bounds for int32"

stack trace:

File ~\AppData\Local\Continuum\anaconda3\envs\qnlp\lib\site-packages\lambeq\training\tket_model.py:103, in TketModel.get_diagram_output(self, diagrams) 93 raise ValueError('Weights and/or symbols not initialised. ' 94 'Instantiate through ' 95 'TketModel.from_diagrams() first, ' 96 'then call initialise_weights(), or load ' 97 'from pre-trained checkpoint.') 99 lambdified_diagrams = [self._make_lambda(d) for d in diagrams] 100 tensors = Circuit.eval( 101 [diag_f(self.weights) for diag_f in lambdified_diagrams], 102 **self.backend_config, --> 103 seed=self._randint() 104 ) 105 self.backend_config['backend'].empty_cache() 106 # discopy evals a single diagram into a single result 107 # and not a list of results

File ~\AppData\Local\Continuum\anaconda3\envs\qnlp\lib\site-packages\lambeq\training\tket_model.py:71, in TketModel._randint(self, low, high) 70 def _randint(self, low=-1 << 63, high=(1 << 63)-1): ---> 71 return np.random.randint(low, high)

y-richie-y commented 2 years ago

Hi @RoshniRM, thanks for reporting on the issue! We have a fix for this issue, it will be included in the next release. Meanwhile, please change ~\AppData\Local\Continuum\anaconda3\envs\qnlp\lib\site-packages\lambeq\training\tket_model.py:71 to the following:

    return np.random.randint(low, high, dtype=np.int64)
RoshniRM commented 2 years ago

thanks. I made the change and it works!