-
Notifications
You must be signed in to change notification settings - Fork 92
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
Cannot set memory = True for Qiskit backends #225
Comments
This is the code I want to run: Source Codefrom qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, transpile
from azure.quantum.qiskit import AzureQuantumProvider
provider = AzureQuantumProvider(
resource_id="My_ID",
location="japaneast"
)
print([backend.name() for backend in provider.backends()])
q_reg = QuantumRegister(2, 'q')
c_reg = ClassicalRegister(2, 'c')
circuit = QuantumCircuit(q_reg, c_reg)
circuit.name = 'Hello Microsoft Azure Quantum & Honeywell'
circuit.h(0)
circuit.cx(0, 1)
circuit.measure([0, 1], [0, 1])
# Print out the circuit
print(circuit.draw())
backend = provider.get_backend('honeywell.hqs-lt-s1-apival')
result = backend.run(circuit, count=10, memory=True).result()
memory = result.get_memory(circuit)
print(memory) Output:['honeywell.hqs-lt-s1', 'honeywell.hqs-lt-s1-apival', 'honeywell.hqs-lt-s2', 'honeywell.hqs-lt-s2-apival', 'honeywell.hqs-lt-s1-sim']
┌───┐ ┌─┐
q_0: ┤ H ├──■──┤M├───
└───┘┌─┴─┐└╥┘┌─┐
q_1: ─────┤ X ├─╫─┤M├
└───┘ ║ └╥┘
c: 2/═══════════╩══╩═
0 1
memory is not a known attribute of class <class 'azure.quantum._client.models._models_py3.JobDetails'> and will be ignored
.......Traceback (most recent call last):
File "D:\CS\quantam computing\venv\lib\site-packages\qiskit\result\result.py", line 237, in get_memory
memory = self.data(experiment)["memory"]
KeyError: 'memory'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:/CS/quantam computing/Microsoft Azure Quantum/hello MAQ.py", line 22, in <module>
memory = result.get_memory(circuit)
File "D:\CS\quantam computing\venv\lib\site-packages\qiskit\result\result.py", line 249, in get_memory
raise QiskitError(
qiskit.exceptions.QiskitError: 'No memory for experiment "<qiskit.circuit.quantumcircuit.QuantumCircuit object at 0x000001ABB567B700>". Please verify that you either ran a measurement level 2 job with the memory flag set, eg., "memory=True", or a measurement level 0/1 job.'
Process finished with exit code 1 Using with backend = provider.get_backend('honeywell.hqs-lt-s1-apival')
backend._configuration.memory = True
result = backend.run(circuit, count=10).result()
memory = result.get_memory(circuit)
print(memory) Output:"
['honeywell.hqs-lt-s1', 'honeywell.hqs-lt-s1-apival', 'honeywell.hqs-lt-s2', 'honeywell.hqs-lt-s2-apival', 'honeywell.hqs-lt-s1-sim']
┌───┐ ┌─┐
q_0: ┤ H ├──■──┤M├───
└───┘┌─┴─┐└╥┘┌─┐
q_1: ─────┤ X ├─╫─┤M├
└───┘ ║ └╥┘
c: 2/═══════════╩══╩═
0 1
.......Traceback (most recent call last):
File "D:\CS\quantam computing\venv\lib\site-packages\qiskit\result\result.py", line 237, in get_memory
memory = self.data(experiment)["memory"]
KeyError: 'memory'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:/CS/quantam computing/Microsoft Azure Quantum/hello MAQ.py", line 23, in <module>
memory = result.get_memory(circuit)
File "D:\CS\quantam computing\venv\lib\site-packages\qiskit\result\result.py", line 249, in get_memory
raise QiskitError(
qiskit.exceptions.QiskitError: 'No memory for experiment "<qiskit.circuit.quantumcircuit.QuantumCircuit object at 0x000001A68649B700>". Please verify that you either ran a measurement level 2 job with the memory flag set, eg., "memory=True", or a measurement level 0/1 job.'
Process finished with exit code 1 I'm getting the same error |
I'll just add a note that this occurs on IonQ backends as well. |
Workaround proposed by @amirebrahimi: result = random.choices(list(probabilities.keys()), weights=probabilities.values())[0] |
Note that |
Looks like Qiskit is expecting the configuration of all backends to extend BackendConfiguration to report the required configuration settings. Our backends should do the same. Similarly, our backends should also use BackendProperties to report required properties. That being said, there are no current plans to have the backends to support
|
Thanks for replying, Actually, I working on Quantum Random Number Generator using the One Qubit Algorithm, In that if you use One Qubit and in One Shot/Count you will get One N-bit Random Number. # If do like the there is no use of my QuantumRNG Algorithm!
memory = random.choices(list(result.keys()), weights=result.values(), k=100)
print(memory) Will I face the same problem, If I do with Q#? |
Yes, I thought the memory attribute is not passing to the Backend, memory is not a known attribute of class <class 'azure.quantum._client.models._models_py3.JobDetails'> and will be ignored Has @guenp suggested, A potential workaround would be to override backend._configuration.memory = True So I try to override, By using this, backend.configuration().memory = True Resource: After trying this all, I understood that backends are not support get_memory |
Yes, unfortunately this is not currently supported by any of our backends. We are working towards supporting the ability to log intermediate results, which will enable the scenario you are trying to implement, but this is not possible yet. |
I got the solution, It is not the issue with the backend. We can get the data from each count/shot Using:
Output as Example Code:from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from azure.quantum.qiskit import AzureQuantumProvider
provider = AzureQuantumProvider(
resource_id="My_resource_id",
location="japaneast"
)
q_reg = QuantumRegister(3, 'q')
c_reg = ClassicalRegister(3, 'c0')
circuit = QuantumCircuit(q_reg, c_reg)
circuit.name = 'Bell State: Hello Microsoft Azure Quantum & Honeywell'
circuit.h(0)
circuit.cx(0, 1)
circuit.cx(0, 2)
circuit.measure(range(3), range(3))
print(circuit.draw())
backend = provider.get_backend('honeywell.hqs-lt-s1-sim')
job = backend.run(circuit, count=10, )
result = job.result()
counts = result.get_counts()
print(counts)
result_data = job._azure_job.get_results()
print("OUTPUT:", result_data)
print("Data Type:", type(result_data)) Output: ┌───┐ ┌─┐
q_0: ┤ H ├──■────■─────┤M├───
└───┘┌─┴─┐ │ ┌─┐└╥┘
q_1: ─────┤ X ├──┼──┤M├─╫────
└───┘┌─┴─┐└╥┘ ║ ┌─┐
q_2: ──────────┤ X ├─╫──╫─┤M├
└───┘ ║ ║ └╥┘
c0: 3/════════════════╩══╩══╩═
1 0 2
..............{'000': 4, '111': 5, '011': 1}
OUTPUT: {'c0': ['011', '111', '000', '111', '000', '000', '000', '111', '111', '111']}
Data Type: <class 'dict'> Using this we can fix this:
Thank you @Mobius5150, @guenp, @anpaz and Azure Quantum Team |
I'm going to open again this Issue, as getting the counts from the experiment is not the same as turning memory on and getting the values of the measurements of individual results (which is what was originally reported). |
@Saketh-Chandra tried to submit a job to the Honeywell API validator and was not able to run the below code:
This threw an error saying that
JobDetails
has no parametermemory
.We need to add
memory
as an input argument toHoneywellBackend.run
, or pop these configuration parameters from thekwargs
.A potential workaround would be to override
backend.configuration
:@Saketh-Chandra, could you verify if the above workaround works for you?
The text was updated successfully, but these errors were encountered: