コード例 #1
0
ファイル: test_noise.py プロジェクト: timasq/pyquil
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]
コード例 #2
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
コード例 #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.
     """
     # 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
コード例 #4
0
ファイル: test_device.py プロジェクト: zyedmaheen/pyquil
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
コード例 #5
0
ファイル: _main.py プロジェクト: tommoffat/pyquil
    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
        )
コード例 #6
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
コード例 #7
0
ファイル: test_qcs.py プロジェクト: vishalbelsare/pyquil
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
コード例 #8
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
コード例 #9
0
ファイル: test_device.py プロジェクト: zero-cooper/pyquil
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