|
1 | 1 | from bloqade import stim |
| 2 | +from bloqade.stim.emit import EmitStimMain |
| 3 | +from bloqade.stim.parse import loads |
| 4 | +from bloqade.stim.dialects import noise |
2 | 5 |
|
3 | | -from .base import codegen |
| 6 | +emit = EmitStimMain() |
| 7 | + |
| 8 | + |
| 9 | +def codegen(mt): |
| 10 | + # method should not have any arguments! |
| 11 | + emit.initialize() |
| 12 | + emit.run(mt=mt, args=()) |
| 13 | + return emit.get_output() |
4 | 14 |
|
5 | 15 |
|
6 | 16 | def test_noise(): |
@@ -45,7 +55,43 @@ def test_qubit_loss(): |
45 | 55 | def test_correlated_qubit_loss(): |
46 | 56 | @stim.main |
47 | 57 | def test_correlated_qubit_loss(): |
48 | | - stim.correlated_qubit_loss(probs=(0.1,), targets=(0, 1, 2), nonce=3) |
| 58 | + stim.correlated_qubit_loss(probs=(0.1,), targets=(0, 1, 2)) |
49 | 59 |
|
50 | 60 | out = codegen(test_correlated_qubit_loss) |
51 | | - assert out.strip() == "I_ERROR[correlated_loss:3](0.10000000) 0 1 2" |
| 61 | + assert out.strip() == "I_ERROR[correlated_loss:0](0.10000000) 0 1 2" |
| 62 | + |
| 63 | + |
| 64 | +def test_correlated_qubit_loss_multiple(): |
| 65 | + |
| 66 | + @stim.main |
| 67 | + def test_correlated_qubit_loss_multiple(): |
| 68 | + stim.correlated_qubit_loss(probs=(0.1,), targets=(0, 1)) |
| 69 | + stim.correlated_qubit_loss(probs=(0.1,), targets=(2, 3)) |
| 70 | + |
| 71 | + for i in range(2): # repeat the test to ensure the identifier is reset each time |
| 72 | + out = codegen(test_correlated_qubit_loss_multiple).strip() |
| 73 | + print(out) |
| 74 | + assert ( |
| 75 | + out.strip() |
| 76 | + == "I_ERROR[correlated_loss:0](0.10000000) 0 1\n" |
| 77 | + + "I_ERROR[correlated_loss:1](0.10000000) 2 3" |
| 78 | + ) |
| 79 | + |
| 80 | + |
| 81 | +def test_correlated_qubit_codegen_roundtrip(): |
| 82 | + @stim.main |
| 83 | + def test(): |
| 84 | + stim.correlated_qubit_loss(probs=(0.1,), targets=(0, 1, 2)) |
| 85 | + stim.qubit_loss(probs=(0.2,), targets=(2,)) |
| 86 | + stim.correlated_qubit_loss(probs=(0.3,), targets=(3, 4)) |
| 87 | + |
| 88 | + stim_str = codegen(test) |
| 89 | + |
| 90 | + mt = loads( |
| 91 | + stim_str, |
| 92 | + nonstim_noise_ops={ |
| 93 | + "loss": noise.QubitLoss, |
| 94 | + "correlated_loss": noise.CorrelatedQubitLoss, |
| 95 | + }, |
| 96 | + ) |
| 97 | + assert codegen(mt) == stim_str |
0 commit comments