-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
2274 Benchmark User Guide #2566
base: main
Are you sure you want to change the base?
2274 Benchmark User Guide #2566
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @Shivansh20128, thank you for submitting a PR to Mitiq! We will respond as soon as possible, and if you have any questions in the meantime, you can ask us on the Unitary Fund Discord.
Hi! Can someone review this draft PR and reply if this is the kind of documentation the project needs? I will then add the rest of it accordingly. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2566 +/- ##
=======================================
Coverage 98.72% 98.72%
=======================================
Files 92 92
Lines 4168 4168
=======================================
Hits 4115 4115
Misses 53 53 ☔ View full report in Codecov by Sentry. |
@Shivansh20128 this is exactly the kind of thing we're looking for! |
@purva-thakre Can you tell me why this error is coming in the checks performed? This is a different one from the previous check error, which I have linked to an open issue. I don't think its related to the changes I have made, so maybe I am just unlucky to encounter two tests failing non-deterministically🥲 for the two pushes I have made. |
@Shivansh20128 https://github.com/unitaryfund/mitiq/actions/runs/11801809295/job/32876002160?pr=2566 is definitely unrelated to your changes, but it's not even a test that fails non-deterministically, or has anything to do with Mitiq. It looks like Python panicked when calling some core routine written in Rust 😱 Interesting, but definitely not in the scope of this PR 😄 |
Aahh. Okay. Thank you |
I think the error in the docs-build will be resolved once #2570 is merged. |
Co-authored-by: Purva Thakre <[email protected]>
Co-authored-by: Purva Thakre <[email protected]>
Co-authored-by: Purva Thakre <[email protected]>
Co-authored-by: Purva Thakre <[email protected]>
Co-authored-by: Purva Thakre <[email protected]>
Co-authored-by: Purva Thakre <[email protected]>
Co-authored-by: Purva Thakre <[email protected]>
Co-authored-by: Purva Thakre <[email protected]>
Co-authored-by: Purva Thakre <[email protected]>
What are these errors regarding? It mentions something about it being unable to find the docker images locally. |
Which ones? |
Hmm they have stopped now. You can see it here if you want. |
…sh20128/mitiq into 2274-benchmark-user-guide
Upon reading the document shared by @cosenal and based on the discussion on the discord channel, this is the example for Mirror Circuits that I could come up with. Its a bit lengthy example, and does not follow the workflow we design in the beginning of the benchmarks section. from typing import List, Tuple
import numpy as np
import cirq
import networkx as nx
from mitiq import zne
from mitiq import benchmarks
topology = nx.complete_graph(7)
def get_circuit(depth: int) -> Tuple[cirq.Circuit, List[int]]:
circuit, correct_bitstring = benchmarks.generate_mirror_circuit(
nlayers=depth,
two_qubit_gate_prob=1.0,
connectivity_graph=topology,
return_type="cirq",
)
return circuit, correct_bitstring
circuit, correct_bitstring = get_circuit(depth=7)
def execute(
circuit: cirq.Circuit,
correct_bitstring: List[int],
noise_level=0.005,
) -> float:
"""Executes the input circuit(s) and returns ⟨A⟩, where
A = |correct_bitstring⟩⟨correct_bitstring| for each circuit.
"""
noisy_circuit = circuit.with_noise(cirq.depolarize(p=noise_level))
noisy_circuit += cirq.measure(*sorted(circuit.all_qubits()), key="m")
backend = cirq.DensityMatrixSimulator()
backend = cirq.DensityMatrixSimulator()
result = backend.run(noisy_circuit)
expval = result.measurements["m"].tolist().count(correct_bitstring)
return expval
def execute_with_fixed_bitstring(circuit, noise_level=0.005):
return execute(circuit, correct_bitstring, noise_level)
true_value = execute(circuit, correct_bitstring,noise_level=0.0)
noisy_value = execute(circuit, correct_bitstring)
zne_value = zne.execute_with_zne(circuit, execute_with_fixed_bitstring) # Noisy quantum computer + Mitiq
print(f"Error w/o Mitiq: {abs((true_value - noisy_value) / true_value):.3f}")
print(f"Error w Mitiq: {abs((true_value - zne_value) / true_value):.3f}") Can someone review this example, if this looks okay. Also, I am not sure for what circuit size the mitiq application will show improvements, but I noticed better performance for bigger circuits. If that is the case, then I think we should go with depth>7 or 8. Please check the example and let me know what changes it needs. |
|
||
## Randomized Benchmarking Circuits | ||
|
||
The {func}`.generate_rb_circuits` are sequences of random gates (generally Clifford gates), to estimate an average error rate. They’re standard in benchmarking for evaluating how well mitiq’s error mitigation reduces this error rate across different levels of noise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some details about what the state of each circuit is supposed to be? For example, the ideal output of a randomized benchmarking circuit is an identity.
GHZ and W circuits define a state. So, you could use some latex equations to show what the states are supposed to be etc.
We don't want to describe what the addition of noise will do to a circuit. the focus is on the details of the benchmarking circuit. All docstrings link a reference used to define a particular benchmarking circuit. You could use details from these refs if you don't know a lot about these circuits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also use .final_state_vector()
to show the ideal circuit state, which is what we expect it to be.
from mitiq.benchmarks import generate_ghz_circuit
circuit = generate_ghz_circuit(n_qubits=3)
circuit.final_state_vector()
this will spit out the 1-D vector form of a 3 qubit GHZ state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also use
.final_state_vector()
to show the ideal circuit state, which is what we expect it to be.
Yes, I can add this function to the example workflow at the top of the file instead of adding it explicitly inside every circuit, so every circuit's ideal circuit state can be seen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to describe what the addition of noise will do to a circuit. the focus is on the details of the benchmarking circuit. All docstrings link a reference used to define a particular benchmarking circuit. You could use details from these refs if you don't know a lot about these circuits.
Since the section is about benchmarking, I believe we should show improvements with mitiq when compared to a noisy circuit without mitiq. But if you think otherwise, I can remove that part from the examples.
Also, since I have now added .final_state_vector(), shall I still go ahead and add the latex equations to show what the states are supposed to be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The focus is on benchmarking circuits. Not benchmarking the performance of a QEM technique using mitiq.
Description
This PR adds a user guide section for benchmarks.
Closes issue #2274
License
Before opening the PR, please ensure you have completed the following where appropriate.