@@ -361,6 +361,46 @@ def test_cirq_qsim_run(mode: str):
361
361
assert value .shape == (5 , 1 )
362
362
363
363
364
+ def test_qsim_invert_mask ():
365
+ q0 , q1 = cirq .LineQubit .range (2 )
366
+ circuit = cirq .Circuit (
367
+ cirq .measure (q0 , q1 , key = "d" , invert_mask = [False , True ]),
368
+ )
369
+ cirq_sample = cirq .Simulator ().sample (circuit , repetitions = 5 )
370
+ qsim_sample = qsimcirq .QSimSimulator ().sample (circuit , repetitions = 5 )
371
+ assert qsim_sample .equals (cirq_sample )
372
+
373
+
374
+ def test_qsim_invert_mask_different_qubits ():
375
+ q0 , q1 = cirq .LineQubit .range (2 )
376
+ circuit = cirq .Circuit (
377
+ cirq .measure (q1 , key = "a" , invert_mask = [True ]),
378
+ cirq .measure (q0 , key = "b" , invert_mask = [True ]),
379
+ cirq .measure (q0 , q1 , key = "c" , invert_mask = [False , True ]),
380
+ cirq .measure (q1 , q0 , key = "d" , invert_mask = [False , True ]),
381
+ )
382
+ cirq_sample = cirq .Simulator ().sample (circuit , repetitions = 5 )
383
+ qsim_sample = qsimcirq .QSimSimulator ().sample (circuit , repetitions = 5 )
384
+ assert qsim_sample .equals (cirq_sample )
385
+
386
+
387
+ def test_qsim_invert_mask_intermediate_measure ():
388
+ q0 , q1 = cirq .LineQubit .range (2 )
389
+ # The dataframe generated by this should be all zeroes.
390
+ circuit = cirq .Circuit (
391
+ cirq .measure (q0 , q1 , key = "a" , invert_mask = [False , False ]),
392
+ cirq .X (q0 ),
393
+ cirq .measure (q0 , q1 , key = "b" , invert_mask = [True , False ]),
394
+ cirq .X (q1 ),
395
+ cirq .measure (q0 , q1 , key = "c" , invert_mask = [True , True ]),
396
+ cirq .X (q0 ),
397
+ cirq .measure (q0 , q1 , key = "d" , invert_mask = [False , True ]),
398
+ )
399
+ cirq_sample = cirq .Simulator ().sample (circuit , repetitions = 5 )
400
+ qsim_sample = qsimcirq .QSimSimulator ().sample (circuit , repetitions = 5 )
401
+ assert qsim_sample .equals (cirq_sample )
402
+
403
+
364
404
@pytest .mark .parametrize ("mode" , ["noiseless" , "noisy" ])
365
405
def test_qsim_run_vs_cirq_run (mode : str ):
366
406
# Simple circuit, want to check mapping of qubit(s) to their measurements
0 commit comments