Skip to content

Commit

Permalink
adding mirror circuits example
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivansh20128 committed Nov 15, 2024
1 parent e03961a commit 302eea0
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion docs/source/guide/benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def execute(circuit, noise_level=0.005):
)
circuit = benchmarks.generate_ghz_circuit(n_qubits=7) # Call the required benchmark circuit function here
print(circuit.final_state_vector())
print(circuit.final_state_vector()) # Shows the ideal circuit state
true_value = execute(circuit, noise_level=0.0) # Ideal quantum computer
noisy_value = execute(circuit) # Noisy quantum computer
Expand All @@ -59,6 +59,61 @@ print(circuit)

The {func}`.generate_mirror_circuit` involves running a quantum circuit forward and then “mirroring” it (applying the reverse operations). Ideally, this results in returning the system to the initial state, so they’re great for testing if the noise mitigation is effective in preserving information through complex sequences.

```{code-cell} ipython3
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(3)
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=3)
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)
print(circuit)
print(circuit.final_state_vector()) # Shows the ideal circuit state
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}")
```

## Mirror Quantum Volume Circuits

The {func}`.generate_mirror_qv_circuit` is designed to test `quantum volume`, a metric combining circuit depth, number of qubits, and fidelity. These circuits check whether error mitigation techniques help achieve higher effective quantum volumes on noisy devices.
Expand Down

0 comments on commit 302eea0

Please sign in to comment.