Commit 88240516 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Add noise-mitigation example



Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent a064e611
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -12,3 +12,32 @@
- Circuit with an Identity sequence: repeating CNOT gates (no optimization), examining the expectation calculation (theoretical = 1.0) with and without noise mitigation. CLI option to enable noise mitigation on any backend (simulator and IBM)

- Sweeping VQE ansatz: showing the energy values with and without noise mitigation.

## Notes:

- Install mitiq: `pip3 install mitiq`

- Install Qiskit: `pip3 install qiskit`

- Make sure `~/.ibm_config` file is present.

- Noise model JSON generation 
(mitiq performs not very well with device noise model. Hence, use theoretical noise model for demonstration purposes)

```
from qiskit.providers.aer.noise import NoiseModel
import json 

# Use a depolarizing noise model.
noise_model = NoiseModel()
noise_model.add_all_qubit_quantum_error(
    depolarizing_error(0.001, 1),
    ["u1", "u2", "u3"],
)
noise_model.add_all_qubit_quantum_error(
    depolarizing_error(0.01, 2),
    ["cx"],
)
  
print(json.dumps(noise_model.to_dict(True)))
```
 No newline at end of file
+31 −0
Original line number Diff line number Diff line
/// mitiq_noise_mitigation.cpp: Run error mitigation with mitiq ZNE (zero-noise extrapolation)
/// Compile:
/// $ qcor -qpu aer[noise-model:noise_model.json] -shots 8192 -em mitiq-zne
/// mitiq_noise_mitigation.cpp Execute: specify the number of repeating CNOT
/// ./a.out N

// Repeating CNOT's to evaluate noise mitigation.
// This is a do-nothing circuit: qubits should return to the |00> state.
__qpu__ void noisy_zero(qreg q, int cx_count) {
  H(q);
  for (int i = 0; i < cx_count; i++) {
    X::ctrl(q[0], q[1]);
  }
  H(q);
  Measure(q);
}

int main(int argc, char *argv[]) {
  // Default depth
  int CX_depth = 0;

  // Parse number of CX cycles:
  if (argc == 2) {
    CX_depth = std::stoi(argv[1]);
  }
  qreg q = qalloc(2);
  // noisy_zero::print_kernel(q, CX_depth);
  noisy_zero(q, CX_depth);
  // q.print();
  std::cout << "CX depth: " << CX_depth << "; Expectation: " << q.exp_val_z() << "\n";
}
 No newline at end of file
+350 −0
Original line number Diff line number Diff line
{
  "errors": [
    {
      "type": "qerror",
      "operations": [
        "u1"
      ],
      "instructions": [
        [
          {
            "name": "x",
            "qubits": [
              0
            ]
          }
        ],
        [
          {
            "name": "y",
            "qubits": [
              0
            ]
          }
        ],
        [
          {
            "name": "z",
            "qubits": [
              0
            ]
          }
        ],
        [
          {
            "name": "id",
            "qubits": [
              0
            ]
          }
        ]
      ],
      "probabilities": [
        0.00025,
        0.00025,
        0.00025,
        0.99925
      ]
    },
    {
      "type": "qerror",
      "operations": [
        "u2"
      ],
      "instructions": [
        [
          {
            "name": "x",
            "qubits": [
              0
            ]
          }
        ],
        [
          {
            "name": "y",
            "qubits": [
              0
            ]
          }
        ],
        [
          {
            "name": "z",
            "qubits": [
              0
            ]
          }
        ],
        [
          {
            "name": "id",
            "qubits": [
              0
            ]
          }
        ]
      ],
      "probabilities": [
        0.00025,
        0.00025,
        0.00025,
        0.99925
      ]
    },
    {
      "type": "qerror",
      "operations": [
        "u3"
      ],
      "instructions": [
        [
          {
            "name": "x",
            "qubits": [
              0
            ]
          }
        ],
        [
          {
            "name": "y",
            "qubits": [
              0
            ]
          }
        ],
        [
          {
            "name": "z",
            "qubits": [
              0
            ]
          }
        ],
        [
          {
            "name": "id",
            "qubits": [
              0
            ]
          }
        ]
      ],
      "probabilities": [
        0.00025,
        0.00025,
        0.00025,
        0.99925
      ]
    },
    {
      "type": "qerror",
      "operations": [
        "cx"
      ],
      "instructions": [
        [
          {
            "name": "x",
            "qubits": [
              0
            ]
          }
        ],
        [
          {
            "name": "y",
            "qubits": [
              0
            ]
          }
        ],
        [
          {
            "name": "z",
            "qubits": [
              0
            ]
          }
        ],
        [
          {
            "name": "x",
            "qubits": [
              1
            ]
          }
        ],
        [
          {
            "name": "x",
            "qubits": [
              0
            ]
          },
          {
            "name": "x",
            "qubits": [
              1
            ]
          }
        ],
        [
          {
            "name": "y",
            "qubits": [
              0
            ]
          },
          {
            "name": "x",
            "qubits": [
              1
            ]
          }
        ],
        [
          {
            "name": "z",
            "qubits": [
              0
            ]
          },
          {
            "name": "x",
            "qubits": [
              1
            ]
          }
        ],
        [
          {
            "name": "y",
            "qubits": [
              1
            ]
          }
        ],
        [
          {
            "name": "x",
            "qubits": [
              0
            ]
          },
          {
            "name": "y",
            "qubits": [
              1
            ]
          }
        ],
        [
          {
            "name": "y",
            "qubits": [
              0
            ]
          },
          {
            "name": "y",
            "qubits": [
              1
            ]
          }
        ],
        [
          {
            "name": "z",
            "qubits": [
              0
            ]
          },
          {
            "name": "y",
            "qubits": [
              1
            ]
          }
        ],
        [
          {
            "name": "z",
            "qubits": [
              1
            ]
          }
        ],
        [
          {
            "name": "x",
            "qubits": [
              0
            ]
          },
          {
            "name": "z",
            "qubits": [
              1
            ]
          }
        ],
        [
          {
            "name": "y",
            "qubits": [
              0
            ]
          },
          {
            "name": "z",
            "qubits": [
              1
            ]
          }
        ],
        [
          {
            "name": "z",
            "qubits": [
              0
            ]
          },
          {
            "name": "z",
            "qubits": [
              1
            ]
          }
        ],
        [
          {
            "name": "id",
            "qubits": [
              0
            ]
          }
        ]
      ],
      "probabilities": [
        0.0006250000000000001,
        0.0006250000000000001,
        0.0006250000000000001,
        0.0006250000000000001,
        0.0006250000000000001,
        0.0006250000000000001,
        0.0006250000000000001,
        0.0006250000000000001,
        0.0006250000000000001,
        0.0006250000000000001,
        0.0006250000000000001,
        0.0006250000000000001,
        0.0006250000000000001,
        0.0006250000000000001,
        0.0006250000000000001,
        0.9906250000000001
      ]
    }
  ]
}
 No newline at end of file