Skip to content

Commit b3177bc

Browse files
committed
Reformatted using black. Deleted unecessary comments. Renamed NoiseModel serialization format to match the rest of the code.
1 parent e676791 commit b3177bc

File tree

6 files changed

+31
-29
lines changed

6 files changed

+31
-29
lines changed

qiskit_scaleway/backends/aer/backend.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ def __init__(self, provider, client: QaaSClient, platform: QaaSPlatform):
5454

5555
self._target = self._convert_to_target()
5656

57-
### LEGACY qiskit 1.4
58-
# self._target = convert_to_target(
59-
# self._configuration, properties=self._properties, defaults=None, custom_name_mapping=NAME_MAPPING
60-
# )
61-
###
62-
6357
def __repr__(self) -> str:
6458
return f"<AerBackend(name={self.name},num_qubits={self.num_qubits},platform_id={self.id})>"
6559

@@ -130,4 +124,6 @@ def _convert_to_target(self) -> Target:
130124
if conf_dict.get("custom_name_mapping") is None:
131125
conf_dict["custom_name_mapping"] = NAME_MAPPING
132126

133-
return Target.from_configuration(**{k: conf_dict[k] for k in args_lis if k in conf_dict})
127+
return Target.from_configuration(
128+
**{k: conf_dict[k] for k in args_lis if k in conf_dict}
129+
)

qiskit_scaleway/backends/base_job.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ def submit(self, session_id: str) -> None:
9898
if noise_model:
9999
noise_model_dict = _encode_numpy_complex(noise_model.to_dict(False))
100100
noise_model = QaaSNoiseModelData(
101-
serialization_format = QaaSNoiseModelSerializationFormat.PATCHED_JSON,
102-
noise_model_serialization = zlib.compress(json.dumps(noise_model_dict).encode()),
101+
serialization_format=QaaSNoiseModelSerializationFormat.AER_COMPRESSED_JSON,
102+
noise_model_serialization=zlib.compress(
103+
json.dumps(noise_model_dict).encode()
104+
),
103105
)
104106
### Uncomment to use standard JSON serialization, provided there is no more issue with AER deserialization logic
105107
# noise_model = QaaSNoiseModelData(
@@ -224,17 +226,13 @@ def _encode_numpy_complex(obj):
224226
"""
225227
if isinstance(obj, np.ndarray):
226228
return {
227-
'__ndarray__': True,
228-
'data': _encode_numpy_complex(obj.tolist()), # Recursively encode data
229-
'dtype': obj.dtype.name,
230-
'shape': obj.shape,
229+
"__ndarray__": True,
230+
"data": _encode_numpy_complex(obj.tolist()), # Recursively encode data
231+
"dtype": obj.dtype.name,
232+
"shape": obj.shape,
231233
}
232234
elif isinstance(obj, (complex, np.complex128)):
233-
return {
234-
'__complex__': True,
235-
'real': obj.real,
236-
'imag': obj.imag
237-
}
235+
return {"__complex__": True, "real": obj.real, "imag": obj.imag}
238236
elif isinstance(obj, dict):
239237
return {key: _encode_numpy_complex(value) for key, value in obj.items()}
240238
elif isinstance(obj, (list, tuple)):

tests/test_aer_multiple_circuits.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def test_aer_multiple_circuits():
5454
url=os.getenv("QISKIT_SCALEWAY_API_URL"),
5555
)
5656

57-
backend = provider.get_backend(os.getenv("QISKIT_SCALEWAY_BACKEND_NAME", "aer_simulation_pop_c16m128"))
57+
backend = provider.get_backend(
58+
os.getenv("QISKIT_SCALEWAY_BACKEND_NAME", "aer_simulation_pop_c16m128")
59+
)
5860

5961
assert backend is not None
6062

@@ -94,16 +96,16 @@ def _get_noise_model():
9496

9597
# Error probabilities (exaggerated to get a noticeable effect for demonstration)
9698
prob_1 = 0.01 # 1-qubit gate
97-
prob_2 = 0.1 # 2-qubit gate
99+
prob_2 = 0.1 # 2-qubit gate
98100

99101
# Depolarizing quantum errors
100102
error_1 = noise.depolarizing_error(prob_1, 1)
101103
error_2 = noise.depolarizing_error(prob_2, 2)
102104

103105
# Add errors to noise model
104106
noise_model = noise.NoiseModel()
105-
noise_model.add_all_qubit_quantum_error(error_1, ['rz', 'sx', 'x'])
106-
noise_model.add_all_qubit_quantum_error(error_2, ['cx'])
107+
noise_model.add_all_qubit_quantum_error(error_1, ["rz", "sx", "x"])
108+
noise_model.add_all_qubit_quantum_error(error_2, ["cx"])
107109

108110
return noise_model
109111

@@ -131,7 +133,9 @@ def test_aer_with_noise_model():
131133
url=os.getenv("QISKIT_SCALEWAY_API_URL"),
132134
)
133135

134-
backend = provider.get_backend(os.getenv("QISKIT_SCALEWAY_BACKEND_NAME", "aer_simulation_pop_c16m128"))
136+
backend = provider.get_backend(
137+
os.getenv("QISKIT_SCALEWAY_BACKEND_NAME", "aer_simulation_pop_c16m128")
138+
)
135139

136140
assert backend is not None
137141

@@ -159,7 +163,7 @@ def test_aer_with_noise_model():
159163
shots=1000,
160164
max_parallel_experiments=0,
161165
session_id=session_id,
162-
noise_model=_get_noise_model()
166+
noise_model=_get_noise_model(),
163167
).result()
164168

165169
ideal_results = run_ideal_result.results

tests/test_estimator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def test_estimator():
3232
url=os.getenv("QISKIT_SCALEWAY_API_URL"),
3333
)
3434

35-
backend = provider.get_backend(os.getenv("QISKIT_SCALEWAY_BACKEND_NAME", "aer_simulation_pop_c16m128"))
35+
backend = provider.get_backend(
36+
os.getenv("QISKIT_SCALEWAY_BACKEND_NAME", "aer_simulation_pop_c16m128")
37+
)
3638

3739
assert backend is not None
3840

tests/test_qsim_simple_circuit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ def test_qsim_simple_circuit():
2525
url=os.getenv("QISKIT_SCALEWAY_API_URL"),
2626
)
2727

28-
backend = provider.get_backend(os.getenv("QSIM_SCALEWAY_BACKEND_NAME", "qsim_simulation_pop_c16m128"))
28+
backend = provider.get_backend(
29+
os.getenv("QSIM_SCALEWAY_BACKEND_NAME", "qsim_simulation_pop_c16m128")
30+
)
2931

3032
assert backend is not None
3133

tests/test_sampler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def test_sampler():
2929
url=os.getenv("QISKIT_SCALEWAY_API_URL"),
3030
)
3131

32-
backend = provider.get_backend(os.getenv("QISKIT_SCALEWAY_BACKEND_NAME", "aer_simulation_pop_c16m128"))
32+
backend = provider.get_backend(
33+
os.getenv("QISKIT_SCALEWAY_BACKEND_NAME", "aer_simulation_pop_c16m128")
34+
)
3335

3436
assert backend is not None
3537

@@ -49,8 +51,6 @@ def test_sampler():
4951
circuit = iqp(mat)
5052
circuit.measure_all()
5153

52-
# isa_circuit = transpile(circuit, backend=backend, optimization_level=1)
53-
# job = sampler.run([isa_circuit], shots=100)
5454
job = sampler.run([circuit], shots=100)
5555
result = job.result()
5656

0 commit comments

Comments
 (0)