Skip to content

[runtime] QubitPlacer part 1 #4700

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

Merged
merged 8 commits into from
Dec 2, 2021

Conversation

mpharrigan
Copy link
Collaborator

Splitting up #4678

  • The interface: QubitPlacer
  • The fallback: NaiveQubitPlacer
  • runtime hooks

some hacks around #4699

@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Nov 23, 2021
@CirqBot CirqBot added the size: M 50< lines changed <250 label Nov 23, 2021
@mpharrigan mpharrigan force-pushed the 2021-11-qubit-placement-a branch from f3b7a82 to f95de7f Compare November 23, 2021 02:10
@mpharrigan
Copy link
Collaborator Author

factored out named topology stuff in #4701

@mpharrigan mpharrigan marked this pull request as ready for review November 23, 2021 02:14
@mpharrigan mpharrigan requested review from cduck, vtomole, wcourtney and a team as code owners November 23, 2021 02:14
@mpharrigan mpharrigan requested a review from maffoo November 23, 2021 02:14
@mpharrigan
Copy link
Collaborator Author

ptal @MichaelBroughton @tanujkhattar or anyone interested

@MichaelBroughton MichaelBroughton self-assigned this Nov 23, 2021
Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good, just a few high level questions before we merge.

Comment on lines 55 to 62
def place_circuit(
self,
circuit: cirq.AbstractCircuit,
problem_topo: NamedTopology,
shared_rt_info: 'cg.SharedRuntimeInfo',
rs: np.random.RandomState,
) -> Tuple[cirq.FrozenCircuit, Dict[Any, cirq.Qid]]:
return circuit.freeze(), {q: q for q in circuit.all_qubits()}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why aren't there any strict checks that the resulting circuit is valid under the given topology ? Do we want to allow users to have a Placer totally ignore the Topology ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes; this placer totally ignores the topology. Validation can be done by the device as part of the execution loop

logger = _PrintLogger(n_total=len(executable_group))
logger.initialize()

rs = np.random.RandomState(rt_config.random_seed)
exe: QuantumExecutable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this declaration mess with the below loop ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is how you do type annotations for loop variables

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this annotation? Wouldn't the type of exe get inferred automatically based on the type of executable_group which we iterating on?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pycharm wasn't picking it up

logger = _PrintLogger(n_total=len(executable_group))
logger.initialize()

rs = np.random.RandomState(rt_config.random_seed)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Should we give the seed to the rt_config or the randomstate generator itself ? It seems like down the line if we kept creating randomStates off of this seed we'd get a lot of duplicate random numbers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two part answer

  1. rt_config needs to be serializable and put in a database so we can groupby and agg the results. Seed is (much!) easier than the internal state of a random state
  2. We don't create >1 randomstate based on this seed. We create one at the top of the function (here!) and it gets passed to any subroutines that require randomness.



@dataclasses.dataclass(frozen=True)
class NaiveQubitPlacer(QubitPlacer):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename the class to a more descriptive name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have a suggestion

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe NoOpQubitPlacer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not really a "no op", it's more like an identity

@mpharrigan
Copy link
Collaborator Author

@MichaelBroughton ptal

I've also merged in #4377 #4701

Comment on lines 23 to 24
from cirq import _compat
from cirq.devices import GridQubit, LineQubit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Duplicate imports? See lines 23-24 below

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #4701 but I don't think there's any post merge duplication

Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once the duplicate import is gone.

@mpharrigan mpharrigan added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Dec 2, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Dec 2, 2021
@CirqBot CirqBot merged commit fe7fa12 into quantumlib:master Dec 2, 2021
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Dec 2, 2021
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Splitting up quantumlib#4678 

- The interface: `QubitPlacer`
- The fallback: `NaiveQubitPlacer`
- runtime hooks

some hacks around quantumlib#4699
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining. size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants