Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Collector and PauliSumCollector work with AbstractCircuit #6109

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cirq-core/cirq/work/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import duet
import numpy as np

from cirq import circuits, study, value
from cirq import study, value

if TYPE_CHECKING:
import cirq
Expand All @@ -29,7 +29,7 @@
class CircuitSampleJob:
"""Describes a sampling task."""

def __init__(self, circuit: circuits.Circuit, *, repetitions: int, tag: Any = None):
def __init__(self, circuit: 'cirq.AbstractCircuit', *, repetitions: int, tag: Any = None):
"""Inits CircuitSampleJob.

Args:
Expand Down
17 changes: 9 additions & 8 deletions cirq-core/cirq/work/pauli_sum_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import numpy as np

from cirq import circuits, ops
from cirq import ops
from cirq.work import collector

if TYPE_CHECKING:
Expand All @@ -29,7 +29,7 @@ class PauliSumCollector(collector.Collector):

def __init__(
self,
circuit: 'cirq.Circuit',
circuit: 'cirq.AbstractCircuit',
observable: 'cirq.PauliSumLike',
*,
samples_per_term: int,
Expand Down Expand Up @@ -99,11 +99,12 @@ def estimated_energy(self) -> Union[float, complex]:


def _circuit_plus_pauli_string_measurements(
circuit: 'cirq.Circuit', pauli_string: 'cirq.PauliString'
) -> 'cirq.Circuit':
circuit: 'cirq.AbstractCircuit', pauli_string: 'cirq.PauliString'
) -> 'cirq.AbstractCircuit':
"""A circuit measuring the given observable at the end of the given circuit."""
assert pauli_string
circuit = circuit.copy()
circuit.append(circuits.Moment(pauli_string.to_z_basis_ops()))
circuit.append(circuits.Moment([ops.measure(*sorted(pauli_string.keys()), key='out')]))
return circuit
return circuit.from_moments(
*circuit,
pauli_string.to_z_basis_ops(),
ops.measure(*sorted(pauli_string.keys()), key='out'),
)