STEP 3
The first part of the code returns a value for the cost function, thus making it
available to subsequent code. We then run a simulation and we are not kidding:
20 000 reps.
Interestingly, the weights are random but the outcome is always the same. That is
the law of large numbers at work!!
STEP4
* * *
Had a flash, in the middle of the night, that I had neglected to install Rust for my
anaconda/Jupyter Notebook. I have correced this.
It's actually an elaborate process for windows. One has to install Visual Studio Code
for things to work. As the curent joke goes, but I'm a professional masochist...
in command prompt:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
At a certain point in the installation, one is given three options about how to
proceed with respect to the Visual Code installer. I chose the first: 1 + enter...
* * *
* * *
Asked the new Gemini Flash for qiskit code to track the time involved on simulations.
The working code:
import time
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
# Create a quantum circuit
qc = QuantumCircuit(20, 20)
qc.h(range(20))
qc.measure(range(20), range(20))
# Use AerSimulator (qasm_simulator by default)
simulator = AerSimulator()
# Time the execution (wall-clock time - ALWAYS AVAILABLE)
start_time = time.perf_counter()
job = simulator.run(qc, shots=1024)
result = job.result()
end_time = time.perf_counter()
print(f"Total execution time (wall-clock): {end_time - start_time} seconds")
# Check if timing information is available in the result
if hasattr(result, 'times') and 'simulator' in result.times:
simulator_time = result.times['simulator']
print(f"Simulator time: {simulator_time} seconds")
print(f"Time per shot: {simulator_time / 1024} seconds")
else:
print("Detailed simulator timing information is not available with this configuration.")
# Access backend properties (NEW METHOD)
backend_props = simulator.properties()
if backend_props:
backend_times = backend_props.to_dict().get('backend_times', None)
if backend_times:
print(f"Backend times: {backend_times}")
else:
print("Backend times are not available in backend properties.")
else:
print("Backend properties are not available for this simulator.")
# Example using the 'extended_stabilizer' method (WILL provide timing info)
simulator_ext_stab = AerSimulator(method='extended_stabilizer')
start_time_ext_stab = time.perf_counter()
job_ext_stab = simulator_ext_stab.run(qc, shots=1024)
result_ext_stab = job_ext_stab.result()
end_time_ext_stab = time.perf_counter()
print(f"Total execution time (extended_stabilizer): {end_time_ext_stab - start_time_ext_stab} seconds")
if hasattr(result_ext_stab, 'times') and 'simulator' in result_ext_stab.times:
print(f"Simulator time (extended_stabilizer): {result_ext_stab.times['simulator']} seconds")
print(f"Time per shot (extended_stabilizer): {result_ext_stab.times['simulator'] / 1024} seconds")
else:
print("Detailed simulator timing information is not available.")
Ran three times.
1- As given:
2- Upped the number of qubits to 50:
I want to invert what is shown to highlight areas of lesser computer time:
import numpy as np
import matplotlib.pyplot as plt
# Generate some data (replace this with your actual data)
data = np.random.rand(10, 10)
# Invert the data
inverted_data = np.max(data) - data
# Create the heat map
plt.imshow(inverted_data, cmap='cool', interpolation='nearest')
plt.colorbar()
plt.title('Inverted Heat Map Example')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
No comments:
Post a Comment