Skip to content

Commit

Permalink
remove circuit compression
Browse files Browse the repository at this point in the history
  • Loading branch information
NoureldinYosri committed Jan 30, 2024
1 parent 91d5bd1 commit 1e744bf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
7 changes: 0 additions & 7 deletions cirq-core/cirq/transformers/optimize_for_target_gateset.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def optimize_for_target_gateset(
gateset: Optional['cirq.CompilationTargetGateset'] = None,
ignore_failures: bool = True,
max_num_passes: Union[int, None] = 1,
preserve_moment_structure: bool = True,
) -> 'cirq.Circuit':
"""Transforms the given circuit into an equivalent circuit using gates accepted by `gateset`.
Expand All @@ -126,7 +125,6 @@ def optimize_for_target_gateset(
conversion failures raise a ValueError.
max_num_passes: The maximum number of passes to do. A value of `None` means to keep
iterating until no further improvements can be made.
preserve_moment_structure: Whether to preserve moment structure or not.
Returns:
An equivalent circuit containing gates accepted by `gateset`.
Expand Down Expand Up @@ -160,11 +158,6 @@ def _outerloop():
for transformer in gateset.postprocess_transformers:
circuit = transformer(circuit, context=context)

if not preserve_moment_structure:
circuit = circuits.Circuit(
op for op in circuit.all_operations()
) # Contract the moments.

num_moments, num_ops = len(circuit), len(tuple(circuit.all_operations()))
if (num_moments, num_ops) == (initial_num_moments, initial_num_ops):
# Stop early. No further optimizations can be done.
Expand Down
56 changes: 31 additions & 25 deletions cirq-core/cirq/transformers/optimize_for_target_gateset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,37 +284,43 @@ def test_optimize_for_target_gateset_multiple_passes(max_num_passes: Union[int,
]
)

desired_circuit = cirq.Circuit(
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=-0.5, z_exponent=1.0).on(
cirq.LineQubit(4)
),
cirq.PhasedXZGate(axis_phase_exponent=-1.0, x_exponent=1, z_exponent=0).on(
cirq.LineQubit(1)
desired_circuit = cirq.Circuit.from_moments(
cirq.Moment(
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=-0.5, z_exponent=1.0).on(
cirq.LineQubit(4)
)
),
cirq.PhasedXZGate(axis_phase_exponent=-0.5, x_exponent=0.5, z_exponent=0.0).on(
cirq.LineQubit(2)
cirq.Moment(cirq.CZ(cirq.LineQubit(4), cirq.LineQubit(5))),
cirq.Moment(
cirq.PhasedXZGate(axis_phase_exponent=-1.0, x_exponent=1, z_exponent=0).on(
cirq.LineQubit(1)
),
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=-0.5, z_exponent=1.0).on(
cirq.LineQubit(0)
),
cirq.PhasedXZGate(axis_phase_exponent=-1.0, x_exponent=1, z_exponent=0).on(
cirq.LineQubit(3)
),
cirq.PhasedXZGate(axis_phase_exponent=-0.5, x_exponent=0.5, z_exponent=0.0).on(
cirq.LineQubit(2)
),
),
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=-0.5, z_exponent=1.0).on(
cirq.LineQubit(0)
cirq.Moment(
cirq.CZ(cirq.LineQubit(0), cirq.LineQubit(1)),
cirq.CZ(cirq.LineQubit(2), cirq.LineQubit(3)),
),
cirq.PhasedXZGate(axis_phase_exponent=-1.0, x_exponent=1, z_exponent=0).on(
cirq.LineQubit(3)
cirq.Moment(
cirq.CZ(cirq.LineQubit(2), cirq.LineQubit(1)),
cirq.CZ(cirq.LineQubit(4), cirq.LineQubit(3)),
),
cirq.PhasedXZGate(axis_phase_exponent=-0.5, x_exponent=0.5, z_exponent=0.0).on(
cirq.LineQubit(6)
cirq.Moment(
cirq.PhasedXZGate(axis_phase_exponent=-0.5, x_exponent=0.5, z_exponent=0.0).on(
cirq.LineQubit(6)
)
),
cirq.CZ(cirq.LineQubit(4), cirq.LineQubit(5)),
cirq.CZ(cirq.LineQubit(0), cirq.LineQubit(1)),
cirq.CZ(cirq.LineQubit(2), cirq.LineQubit(3)),
cirq.CZ(cirq.LineQubit(2), cirq.LineQubit(1)),
cirq.CZ(cirq.LineQubit(4), cirq.LineQubit(3)),
cirq.CZ(cirq.LineQubit(6), cirq.LineQubit(5)),
cirq.Moment(cirq.CZ(cirq.LineQubit(6), cirq.LineQubit(5))),
)

got = cirq.optimize_for_target_gateset(
input_circuit,
gateset=gateset,
max_num_passes=max_num_passes,
preserve_moment_structure=False,
input_circuit, gateset=gateset, max_num_passes=max_num_passes
)
assert got == desired_circuit

0 comments on commit 1e744bf

Please sign in to comment.