From 2ae79d10815512ed77cf5936a7dfef27bae1c9d1 Mon Sep 17 00:00:00 2001 From: Gaurav Gyawali Date: Mon, 17 Nov 2025 15:04:22 -0500 Subject: [PATCH 01/11] Added DFL entropy code --- build/lib/recirq/dfl/dfl_entropy.py | 228 ++++++++++++++++++++++++++++ build/lib/recirq/dfl/dfl_enums.py | 49 ++++++ 2 files changed, 277 insertions(+) create mode 100644 build/lib/recirq/dfl/dfl_entropy.py create mode 100644 build/lib/recirq/dfl/dfl_enums.py diff --git a/build/lib/recirq/dfl/dfl_entropy.py b/build/lib/recirq/dfl/dfl_entropy.py new file mode 100644 index 00000000..6262dde9 --- /dev/null +++ b/build/lib/recirq/dfl/dfl_entropy.py @@ -0,0 +1,228 @@ +# Copyright 2025 Google +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Run experiments for measuring second Renyi entropy via randomized measurements +in 1D DFL circuits. +""" + +from typing import Sequence + +import cirq +import numpy as np +import numpy.typing as npt +import os +import pickle + +import cirq.transformers.randomized_measurements as rand_meas + + +def _layer_interaction(grid: Sequence[cirq.GridQubit], + dt: float,) -> cirq.Circuit: + """Implements the ZZZ term of the DFL Hamiltonian + Args: + grid: The 1D sequence of qubits used in the experiment. + dt: The time step size for the Trotterization. + + Returns: + cirq.Circuit for the Trotter evolution of the ZZZ term. + """ + + moment_1 = [] + moment_2 = [] + moment_3 = [] + moment_h = [] + for i in range(0, len(grid) // 2): + q1 = grid[(2 * i)] + q2 = grid[2 * i + 1] + q3 = grid[(2 * i + 2) % n] + moment_1.append(cirq.CZ(q1, q2)) + moment_2.append(cirq.CZ(q3, q2)) + moment_h.append(cirq.H(q2)) + moment_3.append(cirq.rx(2 * dt).on(q2)) + + return cirq.Circuit.from_moments( + cirq.Moment(moment_h), + cirq.Moment(moment_1), + cirq.Moment(moment_2), + cirq.Moment(moment_3), + cirq.Moment(moment_2), + cirq.Moment(moment_1), + cirq.Moment(moment_h)) + + +def _layer_matter_gauge_x( + grid: Sequence[cirq.GridQubit], dt: float, mu: float, h:float) -> cirq.Circuit: + + """Implements the matter and gauge fields + + Args: + grid: The 1D sequence of qubits used in the experiment. + dt: The time step size for the Trotterization. + h: The gauge field strength coefficient. + mu: The matter field strength coefficient. + + Returns: + cirq.Circuit for the Trotter evolution of the matter and gauge fields. + """ + + moment = [] + for i in range(len(grid)): + if i % 2 == 0: + moment.append(cirq.rx(2 * mu*dt).on(grid[i])) + else: + moment.append(cirq.rx(2 * h*dt).on(grid[i])) + return cirq.Circuit.from_moments(cirq.Moment(moment)) + + +def _layer_floquet(grid: Sequence[cirq.GridQubit], + dt: float, + h: float, + mu: float) -> cirq.Circuit: + """Constructs a Trotter circuit for 1D Disorder-Free Localization (DFL) simulation. + + Args: + grid: The 1D sequence of qubits used in the experiment. + dt: The time step size for the Trotterization. + h: The gauge field strength coefficient. + mu: The matter field strength coefficient. + + Returns: + The complete cirq.Circuit for the Trotter evolution. + + """ + return _layer_interaction(grid, + dt) + _layer_matter_gauge_x(grid, dt, mu, h) + + +def initial_state_for_entropy(grid: Sequence[cirq.GridQubit], + matter_config: str) -> cirq.Circuit: + """Circuit for three types of initial states""" + moment = [] + for i in range(len(grid)): + if i % 2 == 0: + if matter_config == "single_sector": + moment.append(cirq.X(grid[i])) + moment.append(cirq.H(grid[i])) + + elif matter_config == 'disordered': + r = np.random.choice([0, 1]) + if r: + moment.append(cirq.X(grid[i])) + moment.append(cirq.H(grid[i])) + + else: + moment.append(cirq.I(grid[i])) + else: + if matter_config == "disordered": + moment.append(cirq.X(grid[i])) + moment.append(cirq.H(grid[i])) + + return cirq.Circuit(moment) + + +def get_1d_dfl_entropy_experiment_circuits( + grid: Sequence[cirq.GridQubit], + initial_state: str, + n_cycle: int, + dt: float, + h: float, + mu: float, + n_basis: int = 100, + gauge_compiling: bool = True) -> Sequence[cirq.Circuit]: + + if initial_state == "single_sector": + initial_circuit = initial_state_for_entropy(grid, "single_sector") + elif initial_state == "superposition": + initial_circuit = initial_state_for_entropy(grid, "superposition") + elif initial_state == "disordered": + initial_circuit = initial_state_for_entropy(grid, "disordered") + else: + raise ValueError("Invalid initial state") + + circuits = [] + circ = initial_circuit + _layer_floquet(grid, dt, h, mu)*n_cycle + + for _ in range(n_basis): + circ_randomized = rand_meas.RandomizedMeasurements()( + circ, unitary_ensemble="Clifford") + + if gauge_compiling: + circ_randomized = cirq.transformers.gauge_compiling.CZGaugeTransformer( + circ_randomized + ) + + circ_merged = cirq.merge_single_qubit_moments_to_phxz(circ_randomized) + circuits.append(circ_merged) + + return circuits + + +def run_1d_dfl_entropy_experiment_circuits( + grid: Sequence[cirq.GridQubit], + initial_states: Sequence[str], + save_dir: str, + n_cycles: Sequence[int] | npt.NDArray, + dt: float, + h: float, + mu: float, + n_basis: int = 100, + n_shots: int = 1000, + sampler: cirq.Sampler = cirq.Simulator(), + gauge_compiling: bool = True) -> None: + + if not os.path.isdir(save_dir + "/dt{:.2f}".format(dt)): + os.mkdir(save_dir + "/dt{:.2f}".format(dt)) + + if not os.path.isdir(save_dir + + "/dt{:.2f}/h{:.2f}_mu{:.2f}".format(dt, h, mu)): + os.mkdir( + save_dir + "/dt{:.2f}/h{:.2f}_mu{:.2f}".format(dt, h, mu)) + + for initial_state in initial_states: + if not os.path.isdir( + save_dir + + "/dt{:.2f}/h{:.2f}_mu{:.2f}/{:s}".format( + dt, + h, + mu, + initial_state)): + os.mkdir( + save_dir + + "/dt{:.2f}/h{:.2f}_mu{:.2f}/{:s}".format( + dt, + h, + mu, + initial_state)) + + for n_cycle in n_cycles: + print(initial_state, n_cycle) + fname = ( + save_dir + + "/dt{:.2f}/h{:.2f}_mu{:.2f}/{:s}/cycle{}.pickle".format( + dt, h, mu, initial_state, n_cycle + ) + ) + circuits = get_1d_dfl_entropy_experiment_circuits(grid, initial_state=initial_state, + n_cycle=n_cycle, dt=dt, h=h, mu=mu, + n_basis=n_basis, gauge_compiling=gauge_compiling) + + results = sampler.run_batch(circuits, repetitions=n_shots) + bitstrings = [] + for j in range(n_basis): + bitstrings.append( + results[j][0].measurements["m"]) + + with open(fname, "wb") as myfile: + pickle.dump(bitstrings, myfile) + return None diff --git a/build/lib/recirq/dfl/dfl_enums.py b/build/lib/recirq/dfl/dfl_enums.py new file mode 100644 index 00000000..e0c6793f --- /dev/null +++ b/build/lib/recirq/dfl/dfl_enums.py @@ -0,0 +1,49 @@ +# Copyright 2025 Google +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Enums defining the core gates, states, and bases for +the Disorder-Free Localization (DFL) experiment. +""" + +import enum + +class TwoQubitGate(enum.Enum): + """Available two-qubit gate types for the Trotter simulation. + + CZ refers to the two-qubit 'cz' gate + CPHASE refers to the 'cphase' operation + """ + CZ = 'cz' + CPHASE = 'cphase' + + +class InitialState(enum.Enum): + """Available initial quantum states for the DFL experiment. + + SINGLE_SECTOR refers to the gauge invariant 'single_sector' state + SUPERPOSITION refers to the 'superposition' state of disorder configurations. + """ + SINGLE_SECTOR = 'single_sector' + SUPERPOSITION = 'superposition' + DISORDERED = 'disordered' + + +class Basis(enum.Enum): + """Available bases for the DFL experiment. + + LGT refers to the local lattice gauge theory ('lgt') basis. + DUAL refers to the 'dual' basis. + """ + LGT = 'lgt' + DUAL = 'dual' From f94496dc0b2eddb42afc0967ba3d72f6baff6c04 Mon Sep 17 00:00:00 2001 From: Gaurav Gyawali Date: Mon, 17 Nov 2025 15:16:07 -0500 Subject: [PATCH 02/11] fix the lint error --- recirq/dfl/dfl_entropy.py | 281 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) create mode 100644 recirq/dfl/dfl_entropy.py diff --git a/recirq/dfl/dfl_entropy.py b/recirq/dfl/dfl_entropy.py new file mode 100644 index 00000000..9620bd63 --- /dev/null +++ b/recirq/dfl/dfl_entropy.py @@ -0,0 +1,281 @@ +# Copyright 2025 Google +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Run experiments for measuring second Renyi entropy via randomized measurements +in 1D DFL circuits. +""" + + +import os +import pickle +from collections.abc import Sequence + +import cirq +from cirq.transformers import gauge_compiling, dynamical_decoupling, randomized_measurements +import numpy as np +import numpy.typing as npt + +from recirq.dfl.dfl_enums import InitialState + + +def _layer_interaction(grid: Sequence[cirq.GridQubit], + dt: float,) -> cirq.Circuit: + """Implements the ZZZ term of the DFL Hamiltonian + Args: + grid: The 1D sequence of qubits used in the experiment. + dt: The time step size for the Trotterization. + + Returns: + cirq.Circuit for the Trotter evolution of the ZZZ term. + """ + + moment_1 = [] + moment_2 = [] + moment_3 = [] + moment_h = [] + for i in range(0, len(grid) // 2): + q1 = grid[(2 * i)] + q2 = grid[2 * i + 1] + q3 = grid[(2 * i + 2) % len(grid)] + moment_1.append(cirq.CZ(q1, q2)) + moment_2.append(cirq.CZ(q3, q2)) + moment_h.append(cirq.H(q2)) + moment_3.append(cirq.rx(2 * dt).on(q2)) + + return cirq.Circuit.from_moments( + cirq.Moment(moment_h), + cirq.Moment(moment_1), + cirq.Moment(moment_2), + cirq.Moment(moment_3), + cirq.Moment(moment_2), + cirq.Moment(moment_1), + cirq.Moment(moment_h)) + + +def _layer_matter_gauge_x( + grid: Sequence[cirq.GridQubit], dt: float, mu: float, h: float) -> cirq.Circuit: + """Implements the matter and gauge fields + + Args: + grid: The 1D sequence of qubits used in the experiment. + dt: The time step size for the Trotterization. + h: The gauge field strength coefficient. + mu: The matter field strength coefficient. + + Returns: + cirq.Circuit for the Trotter evolution of the matter and gauge fields. + """ + + moment = [] + for i in range(len(grid)): + if i % 2 == 0: + moment.append(cirq.rx(2 * mu*dt).on(grid[i])) + else: + moment.append(cirq.rx(2 * h*dt).on(grid[i])) + return cirq.Circuit.from_moments(cirq.Moment(moment)) + + +def _layer_floquet(grid: Sequence[cirq.GridQubit], + dt: float, + h: float, + mu: float) -> cirq.Circuit: + """Constructs a Trotter circuit for 1D Disorder-Free Localization (DFL) simulation. + + Args: + grid: The 1D sequence of qubits used in the experiment. + dt: The time step size for the Trotterization. + h: The gauge field strength coefficient. + mu: The matter field strength coefficient. + + Returns: + The complete cirq.Circuit for the Trotter evolution. + + """ + + return _layer_interaction(grid, + dt) + _layer_matter_gauge_x(grid, dt, mu, h) + + +def initial_state_for_entropy(grid: Sequence[cirq.GridQubit], + matter_config: InitialState) -> cirq.Circuit: + """Circuit for three types of initial states: + single_sector: |-> |+> |-> |+>... + superposition: |0> |+> |0> |+>... + disordered: |+/-> |-> |+/->... with randomly chosen |+> or |-> on matter sites + """ + + moment = [] + for i in range(len(grid)): + if i % 2 == 0: + if matter_config.value == InitialState.SINGLE_SECTOR.value: + moment.append(cirq.X(grid[i])) + moment.append(cirq.H(grid[i])) + + elif matter_config.value == InitialState.DISORDERED.value: + r = np.random.choice([0, 1]) + if r: + moment.append(cirq.X(grid[i])) + moment.append(cirq.H(grid[i])) + + else: + moment.append(cirq.I(grid[i])) + else: + if matter_config.value == InitialState.DISORDERED.value: + moment.append(cirq.X(grid[i])) + moment.append(cirq.H(grid[i])) + + return cirq.Circuit(moment) + + +def get_1d_dfl_entropy_experiment_circuits( + grid: Sequence[cirq.GridQubit], + initial_state: str, + ncycles: int, + dt: float, + h: float, + mu: float, + n_basis: int = 100) -> Sequence[cirq.Circuit]: + """Generate the circuit instances the entropy experiment + + Args: + initial_state: Which initial state, either "single_sector" or "superposition" or "disordered. + ncycles: The number of Trotter steps (can be 0). + basis: The basis in which to measure. Either "x" or "z". + dt: Trotter step size. + h: The coefficient on the gauge X term. + mu: The coefficient on the matter sigma_x term. + n_basis: The number of random measurement bases to use. + + Returns: + A list of the circuit instances. + + Raises: + ValueError: If initial_state is not valid. + """ + + if initial_state == "single_sector": + initial_circuit = initial_state_for_entropy( + grid, InitialState.SINGLE_SECTOR) + elif initial_state == "superposition": + initial_circuit = initial_state_for_entropy( + grid, InitialState.SUPERPOSITION) + elif initial_state == "disordered": + initial_circuit = initial_state_for_entropy( + grid, InitialState.DISORDERED) + else: + raise ValueError("Invalid initial state") + + circuits = [] + circ = initial_circuit + _layer_floquet(grid, dt, h, mu)*ncycles + + for _ in range(n_basis): + circ_randomized = randomized_measurements.RandomizedMeasurements()( + circ, unitary_ensemble="Clifford") + + circuits.append(circ_randomized) + + return circuits + + +def run_1d_dfl_entropy_experiment( + grid: Sequence[cirq.GridQubit], + initial_states: Sequence[str], + save_dir: str, + n_cycles: Sequence[int] | npt.NDArray, + dt: float, + h: float, + mu: float, + n_basis: int = 100, + n_shots: int = 1000, + sampler: cirq.Sampler = cirq.Simulator(), + gauge_compile: bool = True, + dynamical_decouple: bool = True) -> None: + """Run the 1D DFL experiment (Fig 4 of the paper). + The paper is available at: https://arxiv.org/abs/2410.06557 + + Attrs: + grid: The qubits to use for the experiment. + initial_states: The list of initial states to use. + save_dir: The directory in which to save the results. + n_cycles: The list of number of Trotter steps to use. + dt: The Trotter step size. + h: The coefficient on the gauge X term. + mu: The coefficient on the matter sigma_x term. + n_basis: The number of random measurement bases to use. + n_shots: The number of measurement shots to use. + sampler: The cirq sampler to use. + gauge_compile: Whether to apply gauge compiling. + dynamical_decouple: Whether to apply dynamical decoupling. + + Returns: + None + """ + + if not os.path.isdir(save_dir + "/dt{:.2f}".format(dt)): + os.mkdir(save_dir + "/dt{:.2f}".format(dt)) + + if not os.path.isdir(save_dir + + "/dt{:.2f}/h{:.2f}_mu{:.2f}".format(dt, h, mu)): + os.mkdir( + save_dir + "/dt{:.2f}/h{:.2f}_mu{:.2f}".format(dt, h, mu)) + + for initial_state in initial_states: + if not os.path.isdir( + save_dir + + "/dt{:.2f}/h{:.2f}_mu{:.2f}/{:s}".format( + dt, + h, + mu, + initial_state)): + os.mkdir( + save_dir + + "/dt{:.2f}/h{:.2f}_mu{:.2f}/{:s}".format( + dt, + h, + mu, + initial_state)) + + for n_cycle in n_cycles: + print(initial_state, n_cycle) + fname = ( + save_dir + + "/dt{:.2f}/h{:.2f}_mu{:.2f}/{:s}/cycle{}.pickle".format( + dt, h, mu, initial_state, n_cycle + ) + ) + circuits = get_1d_dfl_entropy_experiment_circuits(grid, initial_state=initial_state, + ncycles=n_cycle, dt=dt, h=h, mu=mu, + n_basis=n_basis) + + circuits_modified = [] + for i in range(len(circuits)): + circ_i = circuits[i] + + if gauge_compile: + circ_i = gauge_compiling.CZGaugeTransformer( + circ_i) + if dynamical_decouple: + circ_i = dynamical_decoupling.add_dynamical_decoupling( + circ_i) + circuits_modified.append(circ_i) + + results = sampler.run_batch(circuits, repetitions=n_shots) + bitstrings = [] + for j in range(n_basis): + bitstrings.append( + results[j][0].measurements["m"]) + + with open(fname, "wb") as myfile: + pickle.dump(bitstrings, myfile) + return None From 65f5f0a336d37eb52fc9857456dad915ac8bb17e Mon Sep 17 00:00:00 2001 From: Gaurav Gyawali Date: Mon, 17 Nov 2025 15:22:22 -0500 Subject: [PATCH 03/11] fix the lint errors --- build/lib/recirq/dfl/dfl_entropy.py | 228 ---------------------------- build/lib/recirq/dfl/dfl_enums.py | 49 ------ recirq/dfl/dfl_enums.py | 1 + 3 files changed, 1 insertion(+), 277 deletions(-) delete mode 100644 build/lib/recirq/dfl/dfl_entropy.py delete mode 100644 build/lib/recirq/dfl/dfl_enums.py diff --git a/build/lib/recirq/dfl/dfl_entropy.py b/build/lib/recirq/dfl/dfl_entropy.py deleted file mode 100644 index 6262dde9..00000000 --- a/build/lib/recirq/dfl/dfl_entropy.py +++ /dev/null @@ -1,228 +0,0 @@ -# Copyright 2025 Google -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Run experiments for measuring second Renyi entropy via randomized measurements -in 1D DFL circuits. -""" - -from typing import Sequence - -import cirq -import numpy as np -import numpy.typing as npt -import os -import pickle - -import cirq.transformers.randomized_measurements as rand_meas - - -def _layer_interaction(grid: Sequence[cirq.GridQubit], - dt: float,) -> cirq.Circuit: - """Implements the ZZZ term of the DFL Hamiltonian - Args: - grid: The 1D sequence of qubits used in the experiment. - dt: The time step size for the Trotterization. - - Returns: - cirq.Circuit for the Trotter evolution of the ZZZ term. - """ - - moment_1 = [] - moment_2 = [] - moment_3 = [] - moment_h = [] - for i in range(0, len(grid) // 2): - q1 = grid[(2 * i)] - q2 = grid[2 * i + 1] - q3 = grid[(2 * i + 2) % n] - moment_1.append(cirq.CZ(q1, q2)) - moment_2.append(cirq.CZ(q3, q2)) - moment_h.append(cirq.H(q2)) - moment_3.append(cirq.rx(2 * dt).on(q2)) - - return cirq.Circuit.from_moments( - cirq.Moment(moment_h), - cirq.Moment(moment_1), - cirq.Moment(moment_2), - cirq.Moment(moment_3), - cirq.Moment(moment_2), - cirq.Moment(moment_1), - cirq.Moment(moment_h)) - - -def _layer_matter_gauge_x( - grid: Sequence[cirq.GridQubit], dt: float, mu: float, h:float) -> cirq.Circuit: - - """Implements the matter and gauge fields - - Args: - grid: The 1D sequence of qubits used in the experiment. - dt: The time step size for the Trotterization. - h: The gauge field strength coefficient. - mu: The matter field strength coefficient. - - Returns: - cirq.Circuit for the Trotter evolution of the matter and gauge fields. - """ - - moment = [] - for i in range(len(grid)): - if i % 2 == 0: - moment.append(cirq.rx(2 * mu*dt).on(grid[i])) - else: - moment.append(cirq.rx(2 * h*dt).on(grid[i])) - return cirq.Circuit.from_moments(cirq.Moment(moment)) - - -def _layer_floquet(grid: Sequence[cirq.GridQubit], - dt: float, - h: float, - mu: float) -> cirq.Circuit: - """Constructs a Trotter circuit for 1D Disorder-Free Localization (DFL) simulation. - - Args: - grid: The 1D sequence of qubits used in the experiment. - dt: The time step size for the Trotterization. - h: The gauge field strength coefficient. - mu: The matter field strength coefficient. - - Returns: - The complete cirq.Circuit for the Trotter evolution. - - """ - return _layer_interaction(grid, - dt) + _layer_matter_gauge_x(grid, dt, mu, h) - - -def initial_state_for_entropy(grid: Sequence[cirq.GridQubit], - matter_config: str) -> cirq.Circuit: - """Circuit for three types of initial states""" - moment = [] - for i in range(len(grid)): - if i % 2 == 0: - if matter_config == "single_sector": - moment.append(cirq.X(grid[i])) - moment.append(cirq.H(grid[i])) - - elif matter_config == 'disordered': - r = np.random.choice([0, 1]) - if r: - moment.append(cirq.X(grid[i])) - moment.append(cirq.H(grid[i])) - - else: - moment.append(cirq.I(grid[i])) - else: - if matter_config == "disordered": - moment.append(cirq.X(grid[i])) - moment.append(cirq.H(grid[i])) - - return cirq.Circuit(moment) - - -def get_1d_dfl_entropy_experiment_circuits( - grid: Sequence[cirq.GridQubit], - initial_state: str, - n_cycle: int, - dt: float, - h: float, - mu: float, - n_basis: int = 100, - gauge_compiling: bool = True) -> Sequence[cirq.Circuit]: - - if initial_state == "single_sector": - initial_circuit = initial_state_for_entropy(grid, "single_sector") - elif initial_state == "superposition": - initial_circuit = initial_state_for_entropy(grid, "superposition") - elif initial_state == "disordered": - initial_circuit = initial_state_for_entropy(grid, "disordered") - else: - raise ValueError("Invalid initial state") - - circuits = [] - circ = initial_circuit + _layer_floquet(grid, dt, h, mu)*n_cycle - - for _ in range(n_basis): - circ_randomized = rand_meas.RandomizedMeasurements()( - circ, unitary_ensemble="Clifford") - - if gauge_compiling: - circ_randomized = cirq.transformers.gauge_compiling.CZGaugeTransformer( - circ_randomized - ) - - circ_merged = cirq.merge_single_qubit_moments_to_phxz(circ_randomized) - circuits.append(circ_merged) - - return circuits - - -def run_1d_dfl_entropy_experiment_circuits( - grid: Sequence[cirq.GridQubit], - initial_states: Sequence[str], - save_dir: str, - n_cycles: Sequence[int] | npt.NDArray, - dt: float, - h: float, - mu: float, - n_basis: int = 100, - n_shots: int = 1000, - sampler: cirq.Sampler = cirq.Simulator(), - gauge_compiling: bool = True) -> None: - - if not os.path.isdir(save_dir + "/dt{:.2f}".format(dt)): - os.mkdir(save_dir + "/dt{:.2f}".format(dt)) - - if not os.path.isdir(save_dir + - "/dt{:.2f}/h{:.2f}_mu{:.2f}".format(dt, h, mu)): - os.mkdir( - save_dir + "/dt{:.2f}/h{:.2f}_mu{:.2f}".format(dt, h, mu)) - - for initial_state in initial_states: - if not os.path.isdir( - save_dir + - "/dt{:.2f}/h{:.2f}_mu{:.2f}/{:s}".format( - dt, - h, - mu, - initial_state)): - os.mkdir( - save_dir + - "/dt{:.2f}/h{:.2f}_mu{:.2f}/{:s}".format( - dt, - h, - mu, - initial_state)) - - for n_cycle in n_cycles: - print(initial_state, n_cycle) - fname = ( - save_dir - + "/dt{:.2f}/h{:.2f}_mu{:.2f}/{:s}/cycle{}.pickle".format( - dt, h, mu, initial_state, n_cycle - ) - ) - circuits = get_1d_dfl_entropy_experiment_circuits(grid, initial_state=initial_state, - n_cycle=n_cycle, dt=dt, h=h, mu=mu, - n_basis=n_basis, gauge_compiling=gauge_compiling) - - results = sampler.run_batch(circuits, repetitions=n_shots) - bitstrings = [] - for j in range(n_basis): - bitstrings.append( - results[j][0].measurements["m"]) - - with open(fname, "wb") as myfile: - pickle.dump(bitstrings, myfile) - return None diff --git a/build/lib/recirq/dfl/dfl_enums.py b/build/lib/recirq/dfl/dfl_enums.py deleted file mode 100644 index e0c6793f..00000000 --- a/build/lib/recirq/dfl/dfl_enums.py +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2025 Google -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Enums defining the core gates, states, and bases for -the Disorder-Free Localization (DFL) experiment. -""" - -import enum - -class TwoQubitGate(enum.Enum): - """Available two-qubit gate types for the Trotter simulation. - - CZ refers to the two-qubit 'cz' gate - CPHASE refers to the 'cphase' operation - """ - CZ = 'cz' - CPHASE = 'cphase' - - -class InitialState(enum.Enum): - """Available initial quantum states for the DFL experiment. - - SINGLE_SECTOR refers to the gauge invariant 'single_sector' state - SUPERPOSITION refers to the 'superposition' state of disorder configurations. - """ - SINGLE_SECTOR = 'single_sector' - SUPERPOSITION = 'superposition' - DISORDERED = 'disordered' - - -class Basis(enum.Enum): - """Available bases for the DFL experiment. - - LGT refers to the local lattice gauge theory ('lgt') basis. - DUAL refers to the 'dual' basis. - """ - LGT = 'lgt' - DUAL = 'dual' diff --git a/recirq/dfl/dfl_enums.py b/recirq/dfl/dfl_enums.py index ee2804ef..e0c6793f 100644 --- a/recirq/dfl/dfl_enums.py +++ b/recirq/dfl/dfl_enums.py @@ -36,6 +36,7 @@ class InitialState(enum.Enum): """ SINGLE_SECTOR = 'single_sector' SUPERPOSITION = 'superposition' + DISORDERED = 'disordered' class Basis(enum.Enum): From 80e5d1df42cf556b4e4d116fcbe1eb6003a3b6ea Mon Sep 17 00:00:00 2001 From: Gaurav Gyawali Date: Mon, 17 Nov 2025 18:16:14 -0500 Subject: [PATCH 04/11] Addressed Nour's comments --- recirq/dfl/dfl_entropy.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/recirq/dfl/dfl_entropy.py b/recirq/dfl/dfl_entropy.py index 9620bd63..68c40832 100644 --- a/recirq/dfl/dfl_entropy.py +++ b/recirq/dfl/dfl_entropy.py @@ -118,11 +118,11 @@ def initial_state_for_entropy(grid: Sequence[cirq.GridQubit], moment = [] for i in range(len(grid)): if i % 2 == 0: - if matter_config.value == InitialState.SINGLE_SECTOR.value: + if matter_config == InitialState.SINGLE_SECTOR: moment.append(cirq.X(grid[i])) moment.append(cirq.H(grid[i])) - elif matter_config.value == InitialState.DISORDERED.value: + elif matter_config == InitialState.DISORDERED: r = np.random.choice([0, 1]) if r: moment.append(cirq.X(grid[i])) @@ -131,7 +131,7 @@ def initial_state_for_entropy(grid: Sequence[cirq.GridQubit], else: moment.append(cirq.I(grid[i])) else: - if matter_config.value == InitialState.DISORDERED.value: + if matter_config == InitialState.DISORDERED: moment.append(cirq.X(grid[i])) moment.append(cirq.H(grid[i])) @@ -164,15 +164,10 @@ def get_1d_dfl_entropy_experiment_circuits( ValueError: If initial_state is not valid. """ - if initial_state == "single_sector": + if initial_state in ("single_sector", "disordered", "superposition"): initial_circuit = initial_state_for_entropy( - grid, InitialState.SINGLE_SECTOR) - elif initial_state == "superposition": - initial_circuit = initial_state_for_entropy( - grid, InitialState.SUPERPOSITION) - elif initial_state == "disordered": - initial_circuit = initial_state_for_entropy( - grid, InitialState.DISORDERED) + grid, getattr(InitialState, initial_state.upper())) + else: raise ValueError("Invalid initial state") From b71cf3388d9cb84ffe414186fe8d6c4e73937e88 Mon Sep 17 00:00:00 2001 From: Gaurav Gyawali Date: Mon, 17 Nov 2025 22:29:38 -0500 Subject: [PATCH 05/11] Address Doug's comments --- recirq/dfl/dfl_entropy.py | 213 ++++++++++++++++----------------- recirq/dfl/dfl_entropy_test.py | 52 ++++++++ 2 files changed, 158 insertions(+), 107 deletions(-) create mode 100644 recirq/dfl/dfl_entropy_test.py diff --git a/recirq/dfl/dfl_entropy.py b/recirq/dfl/dfl_entropy.py index 68c40832..f3866db3 100644 --- a/recirq/dfl/dfl_entropy.py +++ b/recirq/dfl/dfl_entropy.py @@ -17,24 +17,38 @@ """ -import os -import pickle from collections.abc import Sequence +from pathlib import Path +import pickle import cirq -from cirq.transformers import gauge_compiling, dynamical_decoupling, randomized_measurements +from cirq.transformers import ( + dynamical_decoupling, + gauge_compiling, + randomized_measurements, +) import numpy as np import numpy.typing as npt from recirq.dfl.dfl_enums import InitialState -def _layer_interaction(grid: Sequence[cirq.GridQubit], - dt: float,) -> cirq.Circuit: +def _layer_interaction( + grid: Sequence[cirq.GridQubit], + dt: float, +) -> cirq.Circuit: """Implements the ZZZ term of the DFL Hamiltonian + Each ZZZ term acts on matter-gauge-matter qubits. + The resulting circuit for each term looks like: + 0: ───────@────────────────────────@─────── + │ │ + 1: ───H───@───@───Rx(2 * dt)───@───@───H─── + │ │ + 2: ───────────@────────────────@─────────── + Args: grid: The 1D sequence of qubits used in the experiment. - dt: The time step size for the Trotterization. + dt: The time step size for the Trotterization. Returns: cirq.Circuit for the Trotter evolution of the ZZZ term. @@ -60,12 +74,20 @@ def _layer_interaction(grid: Sequence[cirq.GridQubit], cirq.Moment(moment_3), cirq.Moment(moment_2), cirq.Moment(moment_1), - cirq.Moment(moment_h)) + cirq.Moment(moment_h), + ) def _layer_matter_gauge_x( - grid: Sequence[cirq.GridQubit], dt: float, mu: float, h: float) -> cirq.Circuit: - """Implements the matter and gauge fields + grid: Sequence[cirq.GridQubit], dt: float, h: float, mu: float +) -> cirq.Circuit: + """Implements the X rotation for the matter and gauge qubits. + The resulting circuit should look like: + 0: ──Rx(2*mu*dt)── + + 1: ──Rx(2*h*dt)──── + + 2: ──Rx(2*mu*dt)─── Args: grid: The 1D sequence of qubits used in the experiment. @@ -80,35 +102,34 @@ def _layer_matter_gauge_x( moment = [] for i in range(len(grid)): if i % 2 == 0: - moment.append(cirq.rx(2 * mu*dt).on(grid[i])) + moment.append(cirq.rx(2 * mu * dt).on(grid[i])) else: - moment.append(cirq.rx(2 * h*dt).on(grid[i])) + moment.append(cirq.rx(2 * h * dt).on(grid[i])) return cirq.Circuit.from_moments(cirq.Moment(moment)) -def _layer_floquet(grid: Sequence[cirq.GridQubit], - dt: float, - h: float, - mu: float) -> cirq.Circuit: +def layer_floquet( + grid: Sequence[cirq.GridQubit], dt: float, h: float, mu: float +) -> cirq.Circuit: """Constructs a Trotter circuit for 1D Disorder-Free Localization (DFL) simulation. Args: grid: The 1D sequence of qubits used in the experiment. - dt: The time step size for the Trotterization. - h: The gauge field strength coefficient. - mu: The matter field strength coefficient. + dt: Trotter step size. + h: The coefficient on the gauge X term. + mu: The coefficient on the matter sigma_x term. Returns: The complete cirq.Circuit for the Trotter evolution. """ - return _layer_interaction(grid, - dt) + _layer_matter_gauge_x(grid, dt, mu, h) + return _layer_interaction(grid, dt) + _layer_matter_gauge_x(grid, dt, h, mu) -def initial_state_for_entropy(grid: Sequence[cirq.GridQubit], - matter_config: InitialState) -> cirq.Circuit: +def initial_state_for_entropy( + grid: Sequence[cirq.GridQubit], matter_config: InitialState +) -> cirq.Circuit: """Circuit for three types of initial states: single_sector: |-> |+> |-> |+>... superposition: |0> |+> |0> |+>... @@ -139,44 +160,37 @@ def initial_state_for_entropy(grid: Sequence[cirq.GridQubit], def get_1d_dfl_entropy_experiment_circuits( - grid: Sequence[cirq.GridQubit], - initial_state: str, - ncycles: int, - dt: float, - h: float, - mu: float, - n_basis: int = 100) -> Sequence[cirq.Circuit]: - """Generate the circuit instances the entropy experiment - - Args: - initial_state: Which initial state, either "single_sector" or "superposition" or "disordered. - ncycles: The number of Trotter steps (can be 0). - basis: The basis in which to measure. Either "x" or "z". - dt: Trotter step size. - h: The coefficient on the gauge X term. - mu: The coefficient on the matter sigma_x term. - n_basis: The number of random measurement bases to use. - - Returns: - A list of the circuit instances. - - Raises: - ValueError: If initial_state is not valid. - """ - - if initial_state in ("single_sector", "disordered", "superposition"): - initial_circuit = initial_state_for_entropy( - grid, getattr(InitialState, initial_state.upper())) - - else: - raise ValueError("Invalid initial state") + grid: Sequence[cirq.GridQubit], + initial_state: InitialState, + ncycles: int, + dt: float, + h: float, + mu: float, + n_basis: int = 100, +) -> Sequence[cirq.Circuit]: + """Generate the circuit instances for the entropy experiment + Args: + grid: The qubits to use for the experiment. + initial_state: Which initial state, see `InitialState` enum. + ncycles: The number of Trotter steps (can be 0). + dt: Trotter step size. + h: The coefficient on the gauge X term. + mu: The coefficient on the matter sigma_x term. + n_basis: The number of random measurement bases to use. + + Returns: + A list of the circuit instances. + """ + + initial_circuit = initial_state_for_entropy(grid, initial_state) circuits = [] - circ = initial_circuit + _layer_floquet(grid, dt, h, mu)*ncycles + circ = initial_circuit + layer_floquet(grid, dt, h, mu) * ncycles for _ in range(n_basis): circ_randomized = randomized_measurements.RandomizedMeasurements()( - circ, unitary_ensemble="Clifford") + circ, unitary_ensemble="Clifford" + ) circuits.append(circ_randomized) @@ -184,92 +198,77 @@ def get_1d_dfl_entropy_experiment_circuits( def run_1d_dfl_entropy_experiment( - grid: Sequence[cirq.GridQubit], - initial_states: Sequence[str], - save_dir: str, - n_cycles: Sequence[int] | npt.NDArray, - dt: float, - h: float, - mu: float, - n_basis: int = 100, - n_shots: int = 1000, - sampler: cirq.Sampler = cirq.Simulator(), - gauge_compile: bool = True, - dynamical_decouple: bool = True) -> None: + grid: Sequence[cirq.GridQubit], + initial_states: Sequence[InitialState], + save_dir: Path, + n_cycles: Sequence[int] | npt.NDArray, + dt: float, + h: float, + mu: float, + n_basis: int = 100, + n_shots: int = 1000, + sampler: cirq.Sampler = cirq.Simulator(), + gauge_compile: bool = True, + dynamical_decouple: bool = True, +) -> None: """Run the 1D DFL experiment (Fig 4 of the paper). The paper is available at: https://arxiv.org/abs/2410.06557 + Saves the measurement bitstrings to save_dir. + + Data is saved in the following directory structure: + save_dir/dt{dt}/h{h}_mu{mu}/{initial_state}/cycle{n_cycle}.pickle Attrs: grid: The qubits to use for the experiment. - initial_states: The list of initial states to use. + initial_states: The list of InitialState to use. save_dir: The directory in which to save the results. n_cycles: The list of number of Trotter steps to use. dt: The Trotter step size. h: The coefficient on the gauge X term. mu: The coefficient on the matter sigma_x term. n_basis: The number of random measurement bases to use. - n_shots: The number of measurement shots to use. + n_shots: The number of measurement shots to use. sampler: The cirq sampler to use. gauge_compile: Whether to apply gauge compiling. dynamical_decouple: Whether to apply dynamical decoupling. Returns: - None + None """ - if not os.path.isdir(save_dir + "/dt{:.2f}".format(dt)): - os.mkdir(save_dir + "/dt{:.2f}".format(dt)) - - if not os.path.isdir(save_dir + - "/dt{:.2f}/h{:.2f}_mu{:.2f}".format(dt, h, mu)): - os.mkdir( - save_dir + "/dt{:.2f}/h{:.2f}_mu{:.2f}".format(dt, h, mu)) - for initial_state in initial_states: - if not os.path.isdir( - save_dir + - "/dt{:.2f}/h{:.2f}_mu{:.2f}/{:s}".format( - dt, - h, - mu, - initial_state)): - os.mkdir( - save_dir + - "/dt{:.2f}/h{:.2f}_mu{:.2f}/{:s}".format( - dt, - h, - mu, - initial_state)) + dir_path = ( + save_dir / f"dt{dt:.2f}" / f"h{h:.2f}_mu{mu:.2f}" / initial_state.value + ) + dir_path.mkdir(parents=True, exist_ok=True) for n_cycle in n_cycles: - print(initial_state, n_cycle) - fname = ( - save_dir - + "/dt{:.2f}/h{:.2f}_mu{:.2f}/{:s}/cycle{}.pickle".format( - dt, h, mu, initial_state, n_cycle - ) + print("Initial state:", initial_state.value, "Cycle:", n_cycle) + fname = dir_path / "cycle{}.pickle".format(n_cycle) + circuits = get_1d_dfl_entropy_experiment_circuits( + grid, + initial_state=initial_state, + ncycles=n_cycle, + dt=dt, + h=h, + mu=mu, + n_basis=n_basis, ) - circuits = get_1d_dfl_entropy_experiment_circuits(grid, initial_state=initial_state, - ncycles=n_cycle, dt=dt, h=h, mu=mu, - n_basis=n_basis) circuits_modified = [] for i in range(len(circuits)): circ_i = circuits[i] if gauge_compile: - circ_i = gauge_compiling.CZGaugeTransformer( - circ_i) + circ_i = gauge_compiling.CZGaugeTransformer(circ_i) if dynamical_decouple: - circ_i = dynamical_decoupling.add_dynamical_decoupling( - circ_i) + circ_i = dynamical_decoupling.add_dynamical_decoupling(circ_i) circuits_modified.append(circ_i) results = sampler.run_batch(circuits, repetitions=n_shots) bitstrings = [] for j in range(n_basis): - bitstrings.append( - results[j][0].measurements["m"]) + bitstrings.append(results[j][0].measurements["m"]) with open(fname, "wb") as myfile: pickle.dump(bitstrings, myfile) diff --git a/recirq/dfl/dfl_entropy_test.py b/recirq/dfl/dfl_entropy_test.py new file mode 100644 index 00000000..cd42a97c --- /dev/null +++ b/recirq/dfl/dfl_entropy_test.py @@ -0,0 +1,52 @@ +import cirq +import numpy as np +from recirq.dfl.dfl_entropy import layer_floquet + + +def test_layer_floquet_basic(): + # Create a simple grid of 4 qubits + grid = [cirq.GridQubit(0, i) for i in range(4)] + dt = 0.1 + h = 0.5 + mu = 0.3 + + circuit = layer_floquet(grid, dt, h, mu) + # Check that the output is a cirq.Circuit + assert isinstance(circuit, cirq.Circuit) + # Check that the circuit has operations on all qubits + qubits_in_circuit = set(q for op in circuit.all_operations() for q in op.qubits) + assert set(grid) == qubits_in_circuit + + +def test_layer_floquet_three_qubits_structure(): + # Test for 3 qubits, manually construct the expected circuit and compare + q1, q2, q3 = cirq.LineQubit.range(3) + grid = [q1, q2, q3] + dt = 0.2 + h = 0.4 + mu = 0.6 + + # Manually construct the expected circuit based on layer_interaction and RX layer + expected_circuit = cirq.Circuit( + cirq.H(q2), + cirq.CZ(q1, q2), + cirq.CZ(q3, q2), + cirq.rx(2 * dt).on(q2), + cirq.CZ(q3, q2), + cirq.CZ(q1, q2), + cirq.H(q2), + ) + + expected_circuit += cirq.Circuit.from_moments( + cirq.Moment( + [ + cirq.rx(2 * mu * dt).on(q1), + cirq.rx(2 * h * dt).on(q2), + cirq.rx(2 * mu * dt).on(q3), + ] + ) + ) + + actual_circuit = layer_floquet(grid, dt, h, mu) + + assert actual_circuit == expected_circuit From 088e5fba172bca75ebec00464e9ff3f79f1ba4ef Mon Sep 17 00:00:00 2001 From: Gaurav Gyawali Date: Mon, 17 Nov 2025 23:20:00 -0500 Subject: [PATCH 06/11] Attempt fixing the pytest issue --- recirq/dfl/dfl_entropy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recirq/dfl/dfl_entropy.py b/recirq/dfl/dfl_entropy.py index f3866db3..92542cdc 100644 --- a/recirq/dfl/dfl_entropy.py +++ b/recirq/dfl/dfl_entropy.py @@ -22,8 +22,8 @@ import pickle import cirq +from cirq import add_dynamical_decoupling from cirq.transformers import ( - dynamical_decoupling, gauge_compiling, randomized_measurements, ) @@ -262,7 +262,7 @@ def run_1d_dfl_entropy_experiment( if gauge_compile: circ_i = gauge_compiling.CZGaugeTransformer(circ_i) if dynamical_decouple: - circ_i = dynamical_decoupling.add_dynamical_decoupling(circ_i) + circ_i = add_dynamical_decoupling(circ_i) circuits_modified.append(circ_i) results = sampler.run_batch(circuits, repetitions=n_shots) From 02efad12c16fcb3223595777441949e126d75c63 Mon Sep 17 00:00:00 2001 From: Gaurav Gyawali Date: Mon, 17 Nov 2025 23:50:58 -0500 Subject: [PATCH 07/11] Attempt 2 fixing the pytest issue --- recirq/dfl/dfl_entropy.py | 6 ++---- recirq/dfl/dfl_entropy_test.py | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/recirq/dfl/dfl_entropy.py b/recirq/dfl/dfl_entropy.py index 92542cdc..9a2b9843 100644 --- a/recirq/dfl/dfl_entropy.py +++ b/recirq/dfl/dfl_entropy.py @@ -25,8 +25,8 @@ from cirq import add_dynamical_decoupling from cirq.transformers import ( gauge_compiling, - randomized_measurements, ) +from cirq.transformers.randomized_measurements import RandomizedMeasurements import numpy as np import numpy.typing as npt @@ -188,9 +188,7 @@ def get_1d_dfl_entropy_experiment_circuits( circ = initial_circuit + layer_floquet(grid, dt, h, mu) * ncycles for _ in range(n_basis): - circ_randomized = randomized_measurements.RandomizedMeasurements()( - circ, unitary_ensemble="Clifford" - ) + circ_randomized = RandomizedMeasurements()(circ, unitary_ensemble="Clifford") circuits.append(circ_randomized) diff --git a/recirq/dfl/dfl_entropy_test.py b/recirq/dfl/dfl_entropy_test.py index cd42a97c..6cb4c2cd 100644 --- a/recirq/dfl/dfl_entropy_test.py +++ b/recirq/dfl/dfl_entropy_test.py @@ -1,5 +1,19 @@ +# Copyright 2025 Google +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import cirq -import numpy as np + from recirq.dfl.dfl_entropy import layer_floquet From 4dfbb820ed122158a87d7a162e4b1d242040ddec Mon Sep 17 00:00:00 2001 From: Gaurav Gyawali Date: Mon, 17 Nov 2025 23:58:10 -0500 Subject: [PATCH 08/11] Attempt 3 fixing the pytest issue --- recirq/dfl/dfl_entropy.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/recirq/dfl/dfl_entropy.py b/recirq/dfl/dfl_entropy.py index 9a2b9843..06470ceb 100644 --- a/recirq/dfl/dfl_entropy.py +++ b/recirq/dfl/dfl_entropy.py @@ -23,10 +23,7 @@ import cirq from cirq import add_dynamical_decoupling -from cirq.transformers import ( - gauge_compiling, -) -from cirq.transformers.randomized_measurements import RandomizedMeasurements +from cirq.transformers import gauge_compiling, RandomizedMeasurements import numpy as np import numpy.typing as npt From cb4e8178828f12a20b6112729cd86a2134760b33 Mon Sep 17 00:00:00 2001 From: Gaurav Gyawali Date: Tue, 18 Nov 2025 00:06:10 -0500 Subject: [PATCH 09/11] Attempt 4 fixing the pytest issue --- recirq/dfl/dfl_entropy.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/recirq/dfl/dfl_entropy.py b/recirq/dfl/dfl_entropy.py index 06470ceb..6b3a1467 100644 --- a/recirq/dfl/dfl_entropy.py +++ b/recirq/dfl/dfl_entropy.py @@ -23,7 +23,7 @@ import cirq from cirq import add_dynamical_decoupling -from cirq.transformers import gauge_compiling, RandomizedMeasurements +from cirq.transformers import gauge_compiling import numpy as np import numpy.typing as npt @@ -185,7 +185,9 @@ def get_1d_dfl_entropy_experiment_circuits( circ = initial_circuit + layer_floquet(grid, dt, h, mu) * ncycles for _ in range(n_basis): - circ_randomized = RandomizedMeasurements()(circ, unitary_ensemble="Clifford") + circ_randomized = cirq.transformers.RandomizedMeasurements()( + circ, unitary_ensemble="Clifford" + ) circuits.append(circ_randomized) From 60fad82e6da7f4447b6acefd4ec97b1bd5bab846 Mon Sep 17 00:00:00 2001 From: Gaurav Gyawali Date: Tue, 18 Nov 2025 00:10:54 -0500 Subject: [PATCH 10/11] Attempt 5 fixing the pytest issue --- recirq/dfl/dfl_entropy.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/recirq/dfl/dfl_entropy.py b/recirq/dfl/dfl_entropy.py index 6b3a1467..5c10a769 100644 --- a/recirq/dfl/dfl_entropy.py +++ b/recirq/dfl/dfl_entropy.py @@ -22,7 +22,6 @@ import pickle import cirq -from cirq import add_dynamical_decoupling from cirq.transformers import gauge_compiling import numpy as np import numpy.typing as npt @@ -259,7 +258,7 @@ def run_1d_dfl_entropy_experiment( if gauge_compile: circ_i = gauge_compiling.CZGaugeTransformer(circ_i) if dynamical_decouple: - circ_i = add_dynamical_decoupling(circ_i) + circ_i = cirq.add_dynamical_decoupling(circ_i) circuits_modified.append(circ_i) results = sampler.run_batch(circuits, repetitions=n_shots) From bdaed51ccf19a8cd2f310fd8f0d2ba66417ad5af Mon Sep 17 00:00:00 2001 From: Gaurav Gyawali Date: Tue, 18 Nov 2025 00:20:18 -0500 Subject: [PATCH 11/11] Attempt 6 fixing the pytest issue --- recirq/dfl/dfl_entropy.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/recirq/dfl/dfl_entropy.py b/recirq/dfl/dfl_entropy.py index 5c10a769..9995b899 100644 --- a/recirq/dfl/dfl_entropy.py +++ b/recirq/dfl/dfl_entropy.py @@ -22,7 +22,6 @@ import pickle import cirq -from cirq.transformers import gauge_compiling import numpy as np import numpy.typing as npt @@ -256,7 +255,7 @@ def run_1d_dfl_entropy_experiment( circ_i = circuits[i] if gauge_compile: - circ_i = gauge_compiling.CZGaugeTransformer(circ_i) + circ_i = cirq.transformers.gauge_compiling.CZGaugeTransformer(circ_i) if dynamical_decouple: circ_i = cirq.add_dynamical_decoupling(circ_i) circuits_modified.append(circ_i)