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

Fix wires in definitions #2

Merged
merged 8 commits into from
Nov 16, 2021
Merged

Fix wires in definitions #2

merged 8 commits into from
Nov 16, 2021

Conversation

thisac
Copy link

@thisac thisac commented Nov 15, 2021

Context:
When definining an observable, the wires where seemingly not passed to the declaration unless explicitly declared.

>>> import xir
>>> program = xir.parse_script("obs Z: 1, Z[0]; end;")
>>> observable = program.declarations["obs"][0]
>>> observable.wires
()

Description of the Change:

  • Wires are implicitly added to the declaration if not explicitly declared in a definition.
  • The maximum wire value used in a statement within a definition will be the number of wires declared. E.g., if, within a definition, a single statement is applied on wire 4, then the declared wires will be 0, 1, 2, 3, and 4.
  • Validation now checks that applied wires is a subset of declared wires (they don't need to be equal).
  • All definitions will have declared wires (either explicitly or implicitly).

Benefits:
Wires are now being declared correctly.

Possible Drawbacks:
The validation check for incorrectly using string wires without explicitly declaring wires is gone. Instead, integer wires are implicitly declare, causing applied wires with string labels to not be a subset of the declared wires.

program = xir.parse_script("gate foo[0, 1, 2]; gate bar: foo | [0, a]; end;")
val = xir.Validator(program)
val.run()

Output:

ValidationError: XIR program is invalid: the following issues have been detected:
	-> Definition 'bar' is invalid. Applied wires [0, a] differ from declared wires [0].

Related GitHub Issues:
None

@thisac thisac self-assigned this Nov 15, 2021
@github-actions
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit .github/CHANGELOG.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name and GitHub username in the contributors section.

Copy link
Collaborator

@Mandrenkov Mandrenkov left a comment

Choose a reason for hiding this comment

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

Awesome! 🎉

xir/parser.py Outdated Show resolved Hide resolved
xir/parser.py Outdated Show resolved Hide resolved
xir/parser.py Show resolved Hide resolved
xir/validator.py Show resolved Hide resolved
xir/validator.py Show resolved Hide resolved
xir/validator.py Outdated Show resolved Hide resolved
tests/test_integration.py Show resolved Hide resolved
tests/test_validator.py Outdated Show resolved Hide resolved
tests/test_validator.py Show resolved Hide resolved
tests/test_parser.py Show resolved Hide resolved
@thisac thisac merged commit 19951b8 into main Nov 16, 2021
@thisac thisac deleted the definition_wires branch November 16, 2021 15:36
.github/CHANGELOG.md Show resolved Hide resolved
.github/CHANGELOG.md Show resolved Hide resolved
.github/CHANGELOG.md Show resolved Hide resolved
@thisac thisac mentioned this pull request Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants