@@ -266,19 +266,12 @@ def test_trial_result_str():
266
266
prng = value .parse_random_state (0 ),
267
267
simulation_options = ccq .mps_simulator .MPSOptions (),
268
268
)
269
- assert (
270
- str (
271
- ccq .mps_simulator .MPSTrialResult (
272
- params = cirq .ParamResolver ({}),
273
- measurements = {'m' : np .array ([[1 ]])},
274
- final_simulator_state = final_simulator_state ,
275
- )
276
- )
277
- == """measurements: m=1
278
- output state: TensorNetwork([
279
- Tensor(shape=(2,), inds=('i_0',), tags=oset([])),
280
- ])"""
269
+ result = ccq .mps_simulator .MPSTrialResult (
270
+ params = cirq .ParamResolver ({}),
271
+ measurements = {'m' : np .array ([[1 ]])},
272
+ final_simulator_state = final_simulator_state ,
281
273
)
274
+ assert 'output state: TensorNetwork' in str (result )
282
275
283
276
284
277
def test_trial_result_repr_pretty ():
@@ -293,40 +286,22 @@ def test_trial_result_repr_pretty():
293
286
measurements = {'m' : np .array ([[1 ]])},
294
287
final_simulator_state = final_simulator_state ,
295
288
)
296
- cirq .testing .assert_repr_pretty (
297
- result ,
298
- """measurements: m=1
299
- output state: TensorNetwork([
300
- Tensor(shape=(2,), inds=('i_0',), tags=oset([])),
301
- ])""" ,
302
- )
289
+ cirq .testing .assert_repr_pretty_contains (result , 'output state: TensorNetwork' )
303
290
cirq .testing .assert_repr_pretty (result , "cirq.MPSTrialResult(...)" , cycle = True )
304
291
305
292
306
293
def test_empty_step_result ():
307
294
q0 = cirq .LineQubit (0 )
308
295
sim = ccq .mps_simulator .MPSSimulator ()
309
296
step_result = next (sim .simulate_moment_steps (cirq .Circuit (cirq .measure (q0 ))))
310
- assert (
311
- str (step_result )
312
- == """q(0)=0
313
- TensorNetwork([
314
- Tensor(shape=(2,), inds=('i_0',), tags=oset([])),
315
- ])"""
316
- )
297
+ assert 'TensorNetwork' in str (step_result )
317
298
318
299
319
300
def test_step_result_repr_pretty ():
320
301
q0 = cirq .LineQubit (0 )
321
302
sim = ccq .mps_simulator .MPSSimulator ()
322
303
step_result = next (sim .simulate_moment_steps (cirq .Circuit (cirq .measure (q0 ))))
323
- cirq .testing .assert_repr_pretty (
324
- step_result ,
325
- """q(0)=0
326
- TensorNetwork([
327
- Tensor(shape=(2,), inds=('i_0',), tags=oset([])),
328
- ])""" ,
329
- )
304
+ cirq .testing .assert_repr_pretty_contains (step_result , 'TensorNetwork' )
330
305
cirq .testing .assert_repr_pretty (step_result , "cirq.MPSSimulatorStepResult(...)" , cycle = True )
331
306
332
307
@@ -391,13 +366,8 @@ def test_simulate_moment_steps_sample():
391
366
step ._simulator_state ().to_numpy (),
392
367
np .asarray ([1.0 / math .sqrt (2 ), 0.0 , 1.0 / math .sqrt (2 ), 0.0 ]),
393
368
)
394
- assert (
395
- str (step )
396
- == """TensorNetwork([
397
- Tensor(shape=(2,), inds=('i_0',), tags=oset([])),
398
- Tensor(shape=(2,), inds=('i_1',), tags=oset([])),
399
- ])"""
400
- )
369
+ # There are two "Tensor()" copies in the string.
370
+ assert len (str (step ).split ('Tensor(' )) == 3
401
371
samples = step .sample ([q0 , q1 ], repetitions = 10 )
402
372
for sample in samples :
403
373
assert np .array_equal (sample , [True , False ]) or np .array_equal (
@@ -412,13 +382,8 @@ def test_simulate_moment_steps_sample():
412
382
step ._simulator_state ().to_numpy (),
413
383
np .asarray ([1.0 / math .sqrt (2 ), 0.0 , 0.0 , 1.0 / math .sqrt (2 )]),
414
384
)
415
- assert (
416
- str (step )
417
- == """TensorNetwork([
418
- Tensor(shape=(2, 2), inds=('i_0', 'mu_0_1'), tags=oset([])),
419
- Tensor(shape=(2, 2), inds=('mu_0_1', 'i_1'), tags=oset([])),
420
- ])"""
421
- )
385
+ # There are two "Tensor()" copies in the string.
386
+ assert len (str (step ).split ('Tensor(' )) == 3
422
387
samples = step .sample ([q0 , q1 ], repetitions = 10 )
423
388
for sample in samples :
424
389
assert np .array_equal (sample , [True , True ]) or np .array_equal (
0 commit comments