diff --git a/docs/guides/transpiler-stages.ipynb b/docs/guides/transpiler-stages.ipynb index d2a8a89bcda..9dde665a03b 100644 --- a/docs/guides/transpiler-stages.ipynb +++ b/docs/guides/transpiler-stages.ipynb @@ -128,7 +128,7 @@ { "data": { "image/svg+xml": [ - "" + "" ], "text/plain": [ "
" @@ -150,13 +150,14 @@ "ghz.h(0)\n", "ghz.cx(0, range(1, 15))\n", "\n", - "pass_manager = generate_preset_pass_manager(\n", - " optimization_level=1,\n", - " backend=backend,\n", - " layout_method=\"trivial\", # Fixed layout mapped in circuit order\n", - ")\n", "depths = []\n", - "for _ in range(100):\n", + "for seed in range(100):\n", + " pass_manager = generate_preset_pass_manager(\n", + " optimization_level=1,\n", + " backend=backend,\n", + " layout_method=\"trivial\", # Fixed layout mapped in circuit order\n", + " seed_transpiler=seed, # For reproducible results\n", + " )\n", " depths.append(pass_manager.run(ghz).depth())\n", "\n", "plt.figure(figsize=(8, 6))\n", @@ -206,7 +207,7 @@ { "data": { "image/svg+xml": [ - "" + "" ], "text/plain": [ "
" @@ -261,7 +262,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "native gates:['reset', 'id', 'delay', 'cx', 'if_else', 'measure', 'rz', 'switch_case', 'sx', 'for_loop', 'x']\n" + "native gates:['cx', 'delay', 'for_loop', 'id', 'if_else', 'measure', 'reset', 'rz', 'switch_case', 'sx', 'x']\n" ] }, { @@ -279,7 +280,7 @@ } ], "source": [ - "print(\"native gates:\" + str(backend.operation_names))\n", + "print(\"native gates:\" + str(sorted(backend.operation_names)))\n", "qc = QuantumCircuit(2)\n", "qc.swap(0, 1)\n", "qc.decompose().draw(\"mpl\")" @@ -372,7 +373,7 @@ { "data": { "image/svg+xml": [ - "" + "" ], "text/plain": [ "
" @@ -395,6 +396,7 @@ " pass_manager = generate_preset_pass_manager(\n", " optimization_level=level,\n", " backend=backend,\n", + " seed_transpiler=1234,\n", " )\n", " circ = pass_manager.run(ghz)\n", " depths.append(circ.depth())\n", @@ -463,6 +465,7 @@ " backend=backend,\n", " timing_constraints=backend.target.timing_constraints(),\n", " scheduling_method=\"asap\",\n", + " seed_transpiler=1234,\n", ")\n", "\n", "\n", diff --git a/docs/guides/visualize-results.ipynb b/docs/guides/visualize-results.ipynb index 924842eaea1..61f06c2595b 100644 --- a/docs/guides/visualize-results.ipynb +++ b/docs/guides/visualize-results.ipynb @@ -70,7 +70,9 @@ "from qiskit_aer.primitives import Sampler\n", "\n", "from qiskit import QuantumCircuit\n", - "from qiskit.visualization import plot_histogram" + "from qiskit.visualization import plot_histogram\n", + "\n", + "sampler = Sampler(backend_options={\"seed_simulator\": 1234})" ] }, { @@ -83,7 +85,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "{0: 0.483, 3: 0.517}\n" + "{3: 0.485, 0: 0.515}\n" ] } ], @@ -95,7 +97,7 @@ "bell.measure_all()\n", "\n", "# execute the quantum circuit\n", - "quasi_dists = Sampler().run(bell, shots=1000).result().quasi_dists[0]\n", + "quasi_dists = sampler.run(bell, shots=1000).result().quasi_dists[0]\n", "print(quasi_dists)" ] }, @@ -108,7 +110,7 @@ { "data": { "image/svg+xml": [ - "" + "" ], "text/plain": [ "
" @@ -149,7 +151,7 @@ { "data": { "image/svg+xml": [ - "" + "" ], "text/plain": [ "
" @@ -162,7 +164,7 @@ ], "source": [ "# Execute two-qubit Bell state again\n", - "second_quasi_dists = Sampler().run(bell, shots=1000).result().quasi_dists[0]\n", + "second_quasi_dists = sampler.run(bell, shots=1000).result().quasi_dists[0]\n", "\n", "# Plot results with custom options\n", "plot_histogram(\n", @@ -197,8 +199,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "EstimatorResult(values=array([ 0.41210938, -0.04296875, 0.50976562, 0.03710938, -0.6796875 ,\n", - " 0.046875 , 0.74609375]), metadata=[{'shots': 1024, 'variance': 0.8301658630371094, 'simulator_metadata': [{'time_taken': 0.088026551, 'num_bind_params': 1, 'parallel_state_update': 4, 'parallel_shots': 1, 'required_memory_mb': 1, 'input_qubit_map': [[1, 1], [0, 0]], 'method': 'statevector', 'device': 'CPU', 'num_qubits': 2, 'sample_measure_time': 0.035824906, 'active_input_qubits': [0, 1], 'num_clbits': 2, 'remapped_qubits': False, 'runtime_parameter_bind': False, 'max_memory_mb': 15990, 'noise': 'ideal', 'measure_sampling': True, 'batched_shots_optimization': False, 'fusion': {'applied': False, 'max_fused_qubits': 5, 'threshold': 14, 'enabled': True}}]}, {'shots': 1024, 'variance': 0.9981536865234375, 'simulator_metadata': [{'time_taken': 0.09900014, 'num_bind_params': 1, 'parallel_state_update': 4, 'parallel_shots': 1, 'required_memory_mb': 1, 'input_qubit_map': [[1, 1], [0, 0]], 'method': 'statevector', 'device': 'CPU', 'num_qubits': 2, 'sample_measure_time': 0.032809922, 'active_input_qubits': [0, 1], 'num_clbits': 2, 'remapped_qubits': False, 'runtime_parameter_bind': False, 'max_memory_mb': 15990, 'noise': 'ideal', 'measure_sampling': True, 'batched_shots_optimization': False, 'fusion': {'applied': False, 'max_fused_qubits': 5, 'threshold': 14, 'enabled': True}}]}, {'shots': 1024, 'variance': 0.7401390075683594, 'simulator_metadata': [{'time_taken': 0.111462886, 'num_bind_params': 1, 'parallel_state_update': 4, 'parallel_shots': 1, 'required_memory_mb': 1, 'input_qubit_map': [[1, 1], [0, 0]], 'method': 'statevector', 'device': 'CPU', 'num_qubits': 2, 'sample_measure_time': 0.032796618, 'active_input_qubits': [0, 1], 'num_clbits': 2, 'remapped_qubits': False, 'runtime_parameter_bind': False, 'max_memory_mb': 15990, 'noise': 'ideal', 'measure_sampling': True, 'batched_shots_optimization': False, 'fusion': {'applied': False, 'max_fused_qubits': 5, 'threshold': 14, 'enabled': True}}]}, {'shots': 1024, 'variance': 0.9986228942871094, 'simulator_metadata': [{'time_taken': 0.069538972, 'num_bind_params': 1, 'parallel_state_update': 4, 'parallel_shots': 1, 'required_memory_mb': 1, 'input_qubit_map': [[1, 1], [0, 0]], 'method': 'statevector', 'device': 'CPU', 'num_qubits': 2, 'sample_measure_time': 0.032297138, 'active_input_qubits': [0, 1], 'num_clbits': 2, 'remapped_qubits': False, 'runtime_parameter_bind': False, 'max_memory_mb': 15990, 'noise': 'ideal', 'measure_sampling': True, 'batched_shots_optimization': False, 'fusion': {'applied': False, 'max_fused_qubits': 5, 'threshold': 14, 'enabled': True}}]}, {'shots': 1024, 'variance': 0.53802490234375, 'simulator_metadata': [{'time_taken': 0.066454049, 'num_bind_params': 1, 'parallel_state_update': 4, 'parallel_shots': 1, 'required_memory_mb': 1, 'input_qubit_map': [[1, 1], [0, 0]], 'method': 'statevector', 'device': 'CPU', 'num_qubits': 2, 'sample_measure_time': 0.043781008, 'active_input_qubits': [0, 1], 'num_clbits': 2, 'remapped_qubits': False, 'runtime_parameter_bind': False, 'max_memory_mb': 15990, 'noise': 'ideal', 'measure_sampling': True, 'batched_shots_optimization': False, 'fusion': {'applied': False, 'max_fused_qubits': 5, 'threshold': 14, 'enabled': True}}]}, {'shots': 1024, 'variance': 0.997802734375, 'simulator_metadata': [{'time_taken': 0.085568344, 'num_bind_params': 1, 'parallel_state_update': 4, 'parallel_shots': 1, 'required_memory_mb': 1, 'input_qubit_map': [[1, 1], [0, 0]], 'method': 'statevector', 'device': 'CPU', 'num_qubits': 2, 'sample_measure_time': 0.043340898, 'active_input_qubits': [0, 1], 'num_clbits': 2, 'remapped_qubits': False, 'runtime_parameter_bind': False, 'max_memory_mb': 15990, 'noise': 'ideal', 'measure_sampling': True, 'batched_shots_optimization': False, 'fusion': {'applied': False, 'max_fused_qubits': 5, 'threshold': 14, 'enabled': True}}]}, {'shots': 1024, 'variance': 0.4433441162109375, 'simulator_metadata': [{'time_taken': 0.073523941, 'num_bind_params': 1, 'parallel_state_update': 4, 'parallel_shots': 1, 'required_memory_mb': 1, 'input_qubit_map': [[1, 1], [0, 0]], 'method': 'statevector', 'device': 'CPU', 'num_qubits': 2, 'sample_measure_time': 0.044553507, 'active_input_qubits': [0, 1], 'num_clbits': 2, 'remapped_qubits': False, 'runtime_parameter_bind': False, 'max_memory_mb': 15990, 'noise': 'ideal', 'measure_sampling': True, 'batched_shots_optimization': False, 'fusion': {'applied': False, 'max_fused_qubits': 5, 'threshold': 14, 'enabled': True}}]}])\n" + "EstimatorResult(values=array([ 0.46875 , 0.0390625 , 0.50390625, -0.03125 , -0.70898438,\n", + " 0.00390625, 0.74609375]), metadata=[{'shots': 1024, 'variance': 0.7802734375, 'simulator_metadata': [{'num_bind_params': 1, 'runtime_parameter_bind': False, 'parallel_state_update': 16, 'parallel_shots': 1, 'sample_measure_time': 0.00021514, 'noise': 'ideal', 'batched_shots_optimization': False, 'remapped_qubits': False, 'active_input_qubits': [0, 1], 'device': 'CPU', 'time_taken': 0.000663561, 'measure_sampling': True, 'num_clbits': 2, 'max_memory_mb': 32768, 'input_qubit_map': [[1, 1], [0, 0]], 'num_qubits': 2, 'method': 'statevector', 'required_memory_mb': 1, 'fusion': {'enabled': True, 'threshold': 14, 'applied': False, 'max_fused_qubits': 5}}]}, {'shots': 1024, 'variance': 0.99847412109375, 'simulator_metadata': [{'num_bind_params': 1, 'runtime_parameter_bind': False, 'parallel_state_update': 16, 'parallel_shots': 1, 'sample_measure_time': 0.000168345, 'noise': 'ideal', 'batched_shots_optimization': False, 'remapped_qubits': False, 'active_input_qubits': [0, 1], 'device': 'CPU', 'time_taken': 0.000587515, 'measure_sampling': True, 'num_clbits': 2, 'max_memory_mb': 32768, 'input_qubit_map': [[1, 1], [0, 0]], 'num_qubits': 2, 'method': 'statevector', 'required_memory_mb': 1, 'fusion': {'enabled': True, 'threshold': 14, 'applied': False, 'max_fused_qubits': 5}}]}, {'shots': 1024, 'variance': 0.7460784912109375, 'simulator_metadata': [{'num_bind_params': 1, 'runtime_parameter_bind': False, 'parallel_state_update': 16, 'parallel_shots': 1, 'sample_measure_time': 0.000183198, 'noise': 'ideal', 'batched_shots_optimization': False, 'remapped_qubits': False, 'active_input_qubits': [0, 1], 'device': 'CPU', 'time_taken': 0.000575254, 'measure_sampling': True, 'num_clbits': 2, 'max_memory_mb': 32768, 'input_qubit_map': [[1, 1], [0, 0]], 'num_qubits': 2, 'method': 'statevector', 'required_memory_mb': 1, 'fusion': {'enabled': True, 'threshold': 14, 'applied': False, 'max_fused_qubits': 5}}]}, {'shots': 1024, 'variance': 0.9990234375, 'simulator_metadata': [{'num_bind_params': 1, 'runtime_parameter_bind': False, 'parallel_state_update': 16, 'parallel_shots': 1, 'sample_measure_time': 0.000164142, 'noise': 'ideal', 'batched_shots_optimization': False, 'remapped_qubits': False, 'active_input_qubits': [0, 1], 'device': 'CPU', 'time_taken': 0.000570774, 'measure_sampling': True, 'num_clbits': 2, 'max_memory_mb': 32768, 'input_qubit_map': [[1, 1], [0, 0]], 'num_qubits': 2, 'method': 'statevector', 'required_memory_mb': 1, 'fusion': {'enabled': True, 'threshold': 14, 'applied': False, 'max_fused_qubits': 5}}]}, {'shots': 1024, 'variance': 0.4973411560058594, 'simulator_metadata': [{'num_bind_params': 1, 'runtime_parameter_bind': False, 'parallel_state_update': 16, 'parallel_shots': 1, 'sample_measure_time': 0.000163506, 'noise': 'ideal', 'batched_shots_optimization': False, 'remapped_qubits': False, 'active_input_qubits': [0, 1], 'device': 'CPU', 'time_taken': 0.000548106, 'measure_sampling': True, 'num_clbits': 2, 'max_memory_mb': 32768, 'input_qubit_map': [[1, 1], [0, 0]], 'num_qubits': 2, 'method': 'statevector', 'required_memory_mb': 1, 'fusion': {'enabled': True, 'threshold': 14, 'applied': False, 'max_fused_qubits': 5}}]}, {'shots': 1024, 'variance': 0.9999847412109375, 'simulator_metadata': [{'num_bind_params': 1, 'runtime_parameter_bind': False, 'parallel_state_update': 16, 'parallel_shots': 1, 'sample_measure_time': 0.000200758, 'noise': 'ideal', 'batched_shots_optimization': False, 'remapped_qubits': False, 'active_input_qubits': [0, 1], 'device': 'CPU', 'time_taken': 0.000581137, 'measure_sampling': True, 'num_clbits': 2, 'max_memory_mb': 32768, 'input_qubit_map': [[1, 1], [0, 0]], 'num_qubits': 2, 'method': 'statevector', 'required_memory_mb': 1, 'fusion': {'enabled': True, 'threshold': 14, 'applied': False, 'max_fused_qubits': 5}}]}, {'shots': 1024, 'variance': 0.4433441162109375, 'simulator_metadata': [{'num_bind_params': 1, 'runtime_parameter_bind': False, 'parallel_state_update': 16, 'parallel_shots': 1, 'sample_measure_time': 0.000214086, 'noise': 'ideal', 'batched_shots_optimization': False, 'remapped_qubits': False, 'active_input_qubits': [0, 1], 'device': 'CPU', 'time_taken': 0.000600807, 'measure_sampling': True, 'num_clbits': 2, 'max_memory_mb': 32768, 'input_qubit_map': [[1, 1], [0, 0]], 'num_qubits': 2, 'method': 'statevector', 'required_memory_mb': 1, 'fusion': {'enabled': True, 'threshold': 14, 'applied': False, 'max_fused_qubits': 5}}]}])\n" ] }, { @@ -214,7 +216,7 @@ { "data": { "image/svg+xml": [ - "" + "" ], "text/plain": [ "
" @@ -238,7 +240,8 @@ "observables_labels = [\"ZZ\", \"XX\", \"YZ\", \"ZY\", \"XY\", \"XZ\", \"ZX\"]\n", "observables = [SparsePauliOp(label) for label in observables_labels]\n", "\n", - "result = Estimator().run([qc] * 7, observables).result()\n", + "estimator = Estimator(backend_options={\"seed_simulator\": 1234})\n", + "result = estimator.run([qc] * 7, observables).result()\n", "print(result)\n", "\n", "# Plot using Matplotlib\n", @@ -272,7 +275,7 @@ { "data": { "image/svg+xml": [ - "" + "" ], "text/plain": [ "
"