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

Circuit not runnig by this backend instance. #153

Open
enzokgomes opened this issue Sep 10, 2024 · 1 comment
Open

Circuit not runnig by this backend instance. #153

enzokgomes opened this issue Sep 10, 2024 · 1 comment
Assignees

Comments

@enzokgomes
Copy link

When attempting to run the trainer.fit method with the provided datasets and early stopping parameters, the following error is encountered:

CircuitNotRunError: Circuit corresponding to ResultHandle('1d68d2f5-60a4-48af-b771-51637cd791b3', 0, 3, 'null') has not been run by this backend instance.

This error occurs within the pytket library when trying to retrieve the result of a quantum circuit that has not been executed. The error is raised from the get_result method in the pytket backend.

Steps to Reproduce

  1. Define train_dataset and val_dataset.
  2. Initialize the trainer object.
  3. Call the fit method on the trainer object with the following parameters:
trainer.fit(train_dataset, val_dataset,
            early_stopping_criterion='acc',
            early_stopping_interval=5,
            minimize_criterion=False)

Expected Behavior
The fit method should execute the training process without errors, utilizing the provided datasets and early stopping parameters.

Actual Behavior
The fit method raises a CircuitNotRunError, indicating that a quantum circuit corresponding to a specific ResultHandle has not been executed by the backend instance. This is followed by a KeyError when trying to access the result from the cache.

Error Traceback

---------------------------------------------------------------------------
CircuitNotRunError                        Traceback (most recent call last)
File c:\Users\enzok\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytket\extensions\qiskit\backends\aer.py:344, in _AerBaseBackend.get_result(self, handle, **kwargs)
    343 try:
--> 344     return super().get_result(handle)
    345 except CircuitNotRunError:

File c:\Users\enzok\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytket\backends\backend.py:347, in Backend.get_result(self, handle, **kwargs)
    346     return cast(BackendResult, self._cache[handle]["result"])
--> 347 raise CircuitNotRunError(handle)

CircuitNotRunError: Circuit corresponding to ResultHandle('1d68d2f5-60a4-48af-b771-51637cd791b3', 0, 3, 'null') has not been run by this backend instance.

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
Cell In[8], line 1
----> 1 trainer.fit(train_dataset, val_dataset,
      2             early_stopping_criterion='acc',
      3             early_stopping_interval=5,
      4             minimize_criterion=False)

File c:\Users\enzok\AppData\Local\Programs\Python\Python311\Lib\site-packages\lambeq\training\quantum_trainer.py:204, in QuantumTrainer.fit(self, train_dataset, val_dataset, log_interval, eval_interval, eval_mode, early_stopping_criterion, early_stopping_interval, minimize_criterion, full_timing_report)
    191 def fit(self,
    192         train_dataset: Dataset,
...
    356         "result"
    357     ] = backres
    359 return cast(BackendResult, self._cache[handle]["result"])

KeyError: ResultHandle('1d68d2f5-60a4-48af-b771-51637cd791b3', 1, 3, 'null')

Environment
Python Version: 3.11
pytket Version: 1.32.0
lambeq Version: 0.4.3
Operating System: Windows

The code is shared on: https://github.com/enzokgomes/NLP-quantum-training

@neiljdo neiljdo self-assigned this Sep 11, 2024
@neiljdo
Copy link
Collaborator

neiljdo commented Sep 11, 2024

Hi @enzokgomes,

Can you downgrade to pytket-qiskit~=0.50.0 and see if that works?

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