Skip to content

Remove implicit thread creation in XEB sampling#6643

Merged
NoureldinYosri merged 1 commit into
mainfrom
xeb_threads
Jun 10, 2024
Merged

Remove implicit thread creation in XEB sampling#6643
NoureldinYosri merged 1 commit into
mainfrom
xeb_threads

Conversation

@NoureldinYosri

@NoureldinYosri NoureldinYosri commented Jun 10, 2024

Copy link
Copy Markdown
Collaborator

XEB sampling creates threads inorder to speed sampling up. however this leads to a race condition when the sampler itself uses threads in its internal implementation. This PR removes the implicit behaviour

In a follow up PR I'll make passing a threading pool possible but optional

cc: @eliottrosenberg

@NoureldinYosri NoureldinYosri requested review from a team, cduck, mrwojtek and vtomole as code owners June 10, 2024 18:53
@CirqBot CirqBot added the size: S 10< lines changed <50 label Jun 10, 2024
@codecov

codecov Bot commented Jun 10, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.81%. Comparing base (03aa511) to head (9097ddd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6643      +/-   ##
==========================================
- Coverage   97.81%   97.81%   -0.01%     
==========================================
  Files        1067     1067              
  Lines       91551    91547       -4     
==========================================
- Hits        89550    89545       -5     
- Misses       2001     2002       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@eliottrosenberg

Copy link
Copy Markdown
Collaborator

Thanks, Nour!

new_records = run_batch(task)
if dataset_directory is not None:
os.makedirs(f'{dataset_directory}', exist_ok=True)
protocols.to_json(new_records, f'{dataset_directory}/xeb.{uuid.uuid4()}.json')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would the order of records be useful here?
If so, it would be better to write json at the end when they are all collected in the records list or at least add an enumeration suffix to the filename.

@NoureldinYosri NoureldinYosri Jun 10, 2024

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

without threading the records are written in the same order as their inputs ... using threads with as_completed (the currently) behaviour wrote them in the order they were completed (so randomly) .... adding the suffix can work now but it will break when I reintroduce the optional threading pools ... eitherway this seems to be more of debug feature than anything else

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sounds good, thanks.

@eliottrosenberg - can you chime in if this debugging feature is still needed?

If not, we should consider removing it in a separate PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not following at this level of detail; I am just a user here :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fyi, this part of the library was written 3+ years ago

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see, let's then leave it as is.

@pavoljuhas pavoljuhas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, but please see comment on optional writing of json files.

@NoureldinYosri NoureldinYosri merged commit 5f7881f into main Jun 10, 2024
vmscw pushed a commit to Sonderfall/Cirq that referenced this pull request Jun 14, 2024
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
@pavoljuhas pavoljuhas deleted the xeb_threads branch January 22, 2025 07:29
BichengYing pushed a commit to BichengYing/Cirq that referenced this pull request Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: S 10< lines changed <50

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants