Skip to content
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

Reworking the NoiseModel interface #710

Merged
merged 13 commits into from
Jul 19, 2024
8 changes: 6 additions & 2 deletions pulser-core/pulser/json/abstract_repr/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def _deserialize_register3d(

def _deserialize_noise_model(noise_model_obj: dict[str, Any]) -> NoiseModel:

def convert_complex(obj: list | tuple) -> list:
def convert_complex(obj: Any) -> Any:
if isinstance(obj, (list, tuple)):
return [convert_complex(e) for e in obj]
elif isinstance(obj, dict):
Expand All @@ -423,11 +423,15 @@ def convert_complex(obj: list | tuple) -> list:
for rate, oper in noise_model_obj.pop("eff_noise"):
eff_noise_rates.append(rate)
eff_noise_opers.append(convert_complex(oper))
return pulser.NoiseModel(

noise_types = noise_model_obj.pop("noise_types")
noise_model = pulser.NoiseModel(
**noise_model_obj,
eff_noise_rates=tuple(eff_noise_rates),
eff_noise_opers=tuple(eff_noise_opers),
)
assert set(noise_model.noise_types) == set(noise_types)
return noise_model


def _deserialize_device_object(obj: dict[str, Any]) -> Device | VirtualDevice:
Expand Down
20 changes: 16 additions & 4 deletions pulser-core/pulser/json/abstract_repr/schemas/noise-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
"type": "number"
},
"laser_waist": {
"type": "number"
"type": [
"number",
"null"
]
},
"noise_types": {
"items": {
Expand All @@ -84,16 +87,25 @@
"type": "number"
},
"runs": {
"type": "number"
"type": [
"number",
"null"
]
},
"samples_per_run": {
"type": "number"
"type": [
"number",
"null"
]
},
"state_prep_error": {
"type": "number"
},
"temperature": {
"type": "number"
"type": [
"number",
"null"
]
}
},
"required": [
Expand Down
Loading