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

[Feature Suggestion]Density matrix measurement #227

Open
yezhuoyang opened this issue Feb 3, 2024 · 0 comments
Open

[Feature Suggestion]Density matrix measurement #227

yezhuoyang opened this issue Feb 3, 2024 · 0 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@yezhuoyang
Copy link
Collaborator

During the development of density matrix module, I tried to run the same mnist example on a noise device. I made the following commit:

[Example] Add the minist example that run on noisedevice

However, in the current interface design, the quantum state measurement is not compatible with the measurement on the density matrix, more specifically, I got the following error message:

[2024-02-02 22:54:14.521] Only use the front 75 images as TEST set.
Epoch 1:
Traceback (most recent call last):
  File "C:\Users\yezhu\OneDrive\Desktop\torchquantum\examples\mnist\mnist_noise.py", line 250, in <module>
    main()
  File "C:\Users\yezhu\OneDrive\Desktop\torchquantum\examples\mnist\mnist_noise.py", line 236, in main
    train(dataflow, model, device, optimizer)
  File "C:\Users\yezhu\OneDrive\Desktop\torchquantum\examples\mnist\mnist_noise.py", line 142, in train
    outputs = model(inputs)
  File "C:\Users\yezhu\OneDrive\Desktop\torchquantum\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "C:\Users\yezhu\OneDrive\Desktop\torchquantum\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "C:\Users\yezhu\OneDrive\Desktop\torchquantum\examples\mnist\mnist_noise.py", line 129, in forward
    x = self.measure(qdev)
  File "C:\Users\yezhu\OneDrive\Desktop\torchquantum\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "C:\Users\yezhu\OneDrive\Desktop\torchquantum\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "C:\Users\yezhu\OneDrive\Desktop\torchquantum\torchquantum\measurement\measurements.py", line 324, in forward
    x = expval(qdev, list(range(qdev.n_wires)), [self.obs()] * qdev.n_wires)
  File "C:\Users\yezhu\OneDrive\Desktop\torchquantum\torchquantum\measurement\measurements.py", line 287, in expval
    all_dims = np.arange(qdev.states.dim())
  File "C:\Users\yezhu\OneDrive\Desktop\torchquantum\venv\lib\site-packages\torch\nn\modules\module.py", line 1695, in __getattr__
    raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
AttributeError: 'NoiseDevice' object has no attribute 'states'

The problem is that in the code in the measurement module, all functions assume that we have a state vector device, so it will try to call the "states" member of the device.

measurement/measurements.py

In the new interface design, either we should change the code in the measurement.py, so that it is compatible with the density matrix measurement, or we can directly define some new measurement functions, but also change the code in the forward and backpropagation.

@yezhuoyang yezhuoyang added bug Something isn't working enhancement New feature or request labels Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants