Skip to content

Commit a9be7d7

Browse files
committed
remove rng from class var
1 parent ecb67a0 commit a9be7d7

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

cirq-core/cirq/transformers/gauge_compiling/multi_moment_cphase_gauge.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,12 @@ class CPhaseGaugeTransformerMM(MultiMomentGaugeTransformer):
182182
def __init__(self, supported_gates=_SUPPORTED_GATESET):
183183
super().__init__(target=_TARGET_GATESET, supported_gates=supported_gates)
184184

185-
def sample_left_moment(self, active_qubits: frozenset[ops.Qid]) -> circuits.Moment:
185+
def sample_left_moment(
186+
self, active_qubits: frozenset[ops.Qid], rng: np.random.Generator = np.random.default_rng()
187+
) -> circuits.Moment:
186188
return circuits.Moment(
187189
[
188-
self.rng.choice(
190+
rng.choice(
189191
np.array([ops.I, ops.X, ops.Y, ops.Z], dtype=ops.Gate),
190192
p=[0.25, 0.25, 0.25, 0.25],
191193
).on(q)

cirq-core/cirq/transformers/gauge_compiling/multi_moment_gauge_compiling.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Creates the abstraction for multi moment gauge compiling as a cirq transformer."""
16-
17-
from __future__ import annotations
15+
"""Defines the abstraction for multi-moment gauge compiling as a cirq transformer."""
1816

1917
import abc
2018

19+
from attrs import field, frozen
2120
import numpy as np
2221

2322
from cirq import circuits, ops
@@ -45,7 +44,6 @@ def __init__(
4544
self,
4645
target: ops.Gate | ops.Gateset | ops.GateFamily,
4746
supported_gates: ops.Gateset = ops.Gateset(),
48-
rng: np.random.Generator = np.random.default_rng(),
4947
) -> None:
5048
"""Constructs a MultiMomentGaugeTransformer.
5149
@@ -56,15 +54,13 @@ def __init__(
5654
supported_gates: Determines what other gates, in addition to the target gates,
5755
are permitted within the gauge moments. If a moment contains a gate not found
5856
in either target or supported_gates, it won't be gauged.
59-
rng: A pseudorandom number generator.
6057
"""
6158
self.target = ops.GateFamily(target) if isinstance(target, ops.Gate) else target
6259
self.supported_gates = (
6360
ops.GateFamily(supported_gates)
6461
if isinstance(supported_gates, ops.Gate)
6562
else supported_gates
6663
)
67-
self.rng = rng
6864

6965
@abc.abstractmethod
7066
def gauge_on_moments(self, moments_to_gauge: list[circuits.Moment]) -> list[circuits.Moment]:
@@ -78,11 +74,14 @@ def gauge_on_moments(self, moments_to_gauge: list[circuits.Moment]) -> list[circ
7874
"""
7975

8076
@abc.abstractmethod
81-
def sample_left_moment(self, active_qubits: frozenset[ops.Qid]) -> circuits.Moment:
77+
def sample_left_moment(
78+
self, active_qubits: frozenset[ops.Qid], rng: np.random.Generator
79+
) -> circuits.Moment:
8280
"""Samples a random single-qubit moment to be inserted before the target block.
8381
8482
Args:
8583
active_qubits: The qubits on which the sampled gates should be applied.
84+
rng: A pseudorandom number generator.
8685
8786
Returns:
8887
The sampled moment.

0 commit comments

Comments
 (0)