Esempio n. 1
0
def test_noise_model(kraus_model_I_dict, kraus_model_RX90_dict):
    noise_model_dict = {
        "gates": [kraus_model_I_dict, kraus_model_RX90_dict],
        "assignment_probs": {"1": [[1.0, 0.0], [0.0, 1.0]], "0": [[1.0, 0.0], [0.0, 1.0]]},
    }

    nm = NoiseModel.from_dict(noise_model_dict)
    km1 = KrausModel.from_dict(kraus_model_I_dict)
    km2 = KrausModel.from_dict(kraus_model_RX90_dict)
    assert nm == NoiseModel(gates=[km1, km2], assignment_probs={0: np.eye(2), 1: np.eye(2)})
    assert nm.gates_by_name("I") == [km1]
    assert nm.gates_by_name("RX") == [km2]
    assert nm.to_dict() == noise_model_dict
Esempio n. 2
0
def test_noise_model(kraus_model_I_dict, kraus_model_RX90_dict):
    noise_model_dict = {'gates': [kraus_model_I_dict,
                                  kraus_model_RX90_dict],
                        'assignment_probs': {'1': [[1.0, 0.0], [0.0, 1.0]],
                                             '0': [[1.0, 0.0], [0.0, 1.0]]},
                        }

    nm = NoiseModel.from_dict(noise_model_dict)
    km1 = KrausModel.from_dict(kraus_model_I_dict)
    km2 = KrausModel.from_dict(kraus_model_RX90_dict)
    assert nm == NoiseModel(gates=[km1, km2],
                            assignment_probs={0: np.eye(2), 1: np.eye(2)})
    assert nm.gates_by_name('I') == [km1]
    assert nm.gates_by_name('RX') == [km2]
    assert nm.to_dict() == noise_model_dict
Esempio n. 3
0
    def __init__(self, name, raw):
        """
        :param name: name of the device
        :param raw: raw JSON response from the server with additional information about this device.
        """
        self.name = name
        self._raw = raw

        # TODO: Introduce distinction between supported ISAs and target ISA
        self._isa = ISA.from_dict(raw['isa']) if 'isa' in raw and raw['isa'] != {} else None
        self.specs = Specs.from_dict(raw['specs']) if raw.get('specs') else None
        self.noise_model = NoiseModel.from_dict(raw['noise_model']) \
            if raw.get('noise_model') else None
Esempio n. 4
0
 def __init__(self, name, raw):
     """
     :param name: name of the device
     :param raw: raw JSON response from the server with additional information about this device.
     """
     # avoid circular imports
     from pyquil.noise import NoiseModel
     self.name = name
     self._raw = raw
     self.isa = ISA.from_dict(raw['isa']) if 'isa' in raw and raw['isa'] != {} else None
     self.specs = Specs.from_dict(raw['specs']) if raw.get('specs') else None
     self.noise_model = NoiseModel.from_dict(raw['noise_model']) \
         if raw.get('noise_model') else None
Esempio n. 5
0
def decoherance_noise_with_asymettric_ro(isa: ISA):
    """Reimplementation of `add_decoherance_noise` with asymmetric readout.

    For simplicity, we use the default values for T1, T2, gate times, et al. and hard-code
    readout fidelities here.
    """
    gates = gates_in_isa(isa)
    noise_model = _decoherence_noise_model(gates)
    p00 = 0.975
    p11 = 0.911
    aprobs = np.array([[p00, 1 - p00], [1 - p11, p11]])
    aprobs = {q: aprobs for q in noise_model.assignment_probs.keys()}
    return NoiseModel(noise_model.gates, aprobs)
Esempio n. 6
0
def test_noise_model():
    km1 = KrausModel('I', (5., ), (0, 1), [np.array([[1 + 1j]])], 1.0)
    km2 = KrausModel('RX', (np.pi / 2, ), (0, ), [np.array([[1 + 1j]])], 1.0)
    nm = NoiseModel([km1, km2], {0: np.eye(2), 1: np.eye(2)})

    assert nm == NoiseModel.from_dict(nm.to_dict())
    assert nm.gates_by_name("I") == [km1]
    assert nm.gates_by_name("RX") == [km2]
Esempio n. 7
0
    def __init__(self, name: str, raw: Dict[str, Any]):
        """
        :param name: name of the device
        :param raw: raw JSON response from the server with additional information about this device.
        """
        self.name = name
        self._raw = raw

        # TODO: Introduce distinction between supported ISAs and target ISA
        self._isa = ISA.from_dict(raw["isa"]) if "isa" in raw and raw["isa"] != {} else None
        self.specs = Specs.from_dict(raw["specs"]) if raw.get("specs") else None
        self.noise_model = (
            NoiseModel.from_dict(raw["noise_model"]) if raw.get("noise_model") else None
        )
Esempio n. 8
0
def test_qcs_noise_model(qcs_aspen8_isa: InstructionSetArchitecture,
                         noise_model_dict: Dict[str, Any]):
    """
    Test that ``NoiseModel.from_dict`` initializes a ``NoiseModel``, which users may, in turn,
    pass to ``QCSQuantumProcessor`` for later initializing a noisy QVM.
    """

    noise_model = NoiseModel.from_dict(noise_model_dict)
    device = QCSQuantumProcessor("Aspen-8",
                                 qcs_aspen8_isa,
                                 noise_model=noise_model)
    assert device.quantum_processor_id == "Aspen-8"

    assert isinstance(device.noise_model, NoiseModel)
    assert device.noise_model == noise_model
Esempio n. 9
0
def test_device(isa_dict, noise_model_dict):
    device_raw = {'isa': isa_dict,
                  'noise_model': noise_model_dict,
                  'is_online': True,
                  'is_retuning': False}

    device = Device(DEVICE_FIXTURE_NAME, device_raw)
    assert device.name == DEVICE_FIXTURE_NAME

    isa = ISA.from_dict(isa_dict)
    noise_model = NoiseModel.from_dict(noise_model_dict)
    # Device.isa is deprecated, but seemingly this is what we want here
    with pytest.warns(DeprecationWarning):
        assert isinstance(device.isa, ISA)
        assert device.isa == isa
    assert isinstance(device.noise_model, NoiseModel)
    assert device.noise_model == noise_model
Esempio n. 10
0
def test_device(isa_dict, noise_model_dict):
    device_raw = {
        'isa': isa_dict,
        'noise_model': noise_model_dict,
        'is_online': True,
        'is_retuning': False
    }

    device = Device(DEVICE_FIXTURE_NAME, device_raw)
    assert device.name == DEVICE_FIXTURE_NAME

    isa = ISA.from_dict(isa_dict)
    noise_model = NoiseModel.from_dict(noise_model_dict)
    assert isinstance(device.isa, ISA)
    assert device.isa == isa
    assert isinstance(device.noise_model, NoiseModel)
    assert device.noise_model == noise_model
def asymmetric_ro_model(qubits: list,
                        p00: float = 0.95,
                        p11: float = 0.90) -> NoiseModel:
    aprobs = np.array([[p00, 1 - p00], [1 - p11, p11]])
    aprobs = {q: aprobs for q in qubits}
    return NoiseModel([], aprobs)
Esempio n. 12
0
def _modified_decoherence_noise_model(
    gates: Sequence[Gate],
    T1: Union[Dict[int, float], float] = 30e-6,
    T2: Union[Dict[int, float], float] = 30e-6,
    gate_time_1q: float = 50e-9,
    gate_time_2q: float = 150e-09,
    ro_fidelity: Union[Dict[int, float], float] = 0.95,
) -> NoiseModel:
    """
    The default noise parameters

    - T1 = 30 us
    - T2 = 30 us
    - 1q gate time = 50 ns
    - 2q gate time = 150 ns

    are currently typical for near-term devices.

    This function will define new gates and add Kraus noise to these gates. It will translate
    the input program to use the noisy version of the gates.

    :param gates: The gates to provide the noise model for.
    :param T1: The T1 amplitude damping time either globally or in a
        dictionary indexed by qubit id. By default, this is 30 us.
    :param T2: The T2 dephasing time either globally or in a
        dictionary indexed by qubit id. By default, this is also 30 us.
    :param gate_time_1q: The duration of the one-qubit gates, namely RX(+pi/2) and RX(-pi/2).
        By default, this is 50 ns.
    :param gate_time_2q: The duration of the two-qubit gates, namely CZ.
        By default, this is 150 ns.
    :param ro_fidelity: The readout assignment fidelity
        :math:`F = (p(0|0) + p(1|1))/2` either globally or in a dictionary indexed by qubit id.
    :return: A NoiseModel with the appropriate Kraus operators defined.
    """
    all_qubits = set(sum(([t.index for t in g.qubits] for g in gates), []))
    if isinstance(T1, dict):
        all_qubits.update(T1.keys())
    if isinstance(T2, dict):
        all_qubits.update(T2.keys())
    if isinstance(ro_fidelity, dict):
        all_qubits.update(ro_fidelity.keys())

    if not isinstance(T1, dict):
        T1 = {q: T1 for q in all_qubits}

    if not isinstance(T2, dict):
        T2 = {q: T2 for q in all_qubits}

    if not isinstance(ro_fidelity, dict):
        ro_fidelity = {q: ro_fidelity for q in all_qubits}

    kraus_maps = []
    for g in gates:
        targets = tuple(t.index for t in g.qubits)
        key = (g.name, tuple(g.params))
        if g.name in NO_NOISE:
            if not g.dd:
                g.gate_time = gate_time_1q
            continue
        matrix, _ = get_modified_noisy_gate(g.name, g.params)

        if len(targets) == 1:
            if g.gate_time == None:
                g.gate_time = gate_time_1q
            noisy_I = damping_after_dephasing(T1.get(targets[0], INFINITY),
                                              T2.get(targets[0], INFINITY),
                                              g.gate_time)
        else:
            if len(targets) != 2:
                raise ValueError(
                    "Noisy gates on more than 2Q not currently supported")
            if g.gate_time == None:
                g.gate_time = gate_time_2q

            # note this ordering of the tensor factors is necessary due to how the QVM orders
            # the wavefunction basis
            noisy_I = tensor_kraus_maps(
                damping_after_dephasing(T1.get(targets[1], INFINITY),
                                        T2.get(targets[1], INFINITY),
                                        g.gate_time),
                damping_after_dephasing(T1.get(targets[0], INFINITY),
                                        T2.get(targets[0], INFINITY),
                                        g.gate_time))
        kraus_maps.append(
            KrausModel(g.name, tuple(g.params), targets,
                       combine_kraus_maps(noisy_I, [matrix]), 1.0))
    aprobs = {}
    for q, f_ro in ro_fidelity.items():
        aprobs[q] = np.array([[f_ro, 1. - f_ro], [1. - f_ro, f_ro]])

    return NoiseModel(kraus_maps, aprobs)