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

Add an assert method testing entanglement #184

Closed
wants to merge 3 commits into from

Conversation

junnaka51
Copy link
Contributor

@junnaka51 junnaka51 commented Jan 17, 2023

In this PR I add a new assert method assert_not_entangled() testing entanglement.
This raises an assertion error when specific qubit(s) are entangled.

Examples of how to use

In [1]: from quantestpy import QuantestPyCircuit
   ...: from quantestpy.assertion.not_entangled import assert_not_entangled
In [2]: # check all qubits, not entangled
   ...: qc = QuantestPyCircuit(3)
   ...: qc.add_gate({"name": "h", "control_qubit": [], "target_qubit": [0],
   ...:             "control_value": [], "parameter": []})
   ...: qc.add_gate({"name": "x", "control_qubit": [], "target_qubit": [1],
   ...:             "control_value": [], "parameter": []})
   ...: assert_not_entangled(circuit=qc)
In [3]:
In [3]: # check all qubits, entangled
   ...: qc = QuantestPyCircuit(3)
   ...: qc.add_gate({"name": "h", "control_qubit": [], "target_qubit": [0],
   ...:             "control_value": [], "parameter": []})
   ...: qc.add_gate({"name": "x", "control_qubit": [0], "target_qubit": [1],
   ...:             "control_value": [1], "parameter": []})
   ...: assert_not_entangled(circuit=qc)
---------------------------------------------------------------------------
QuantestPyAssertionError                  Traceback (most recent call last)
Cell In [3], line 7
      3 qc.add_gate({"name": "h", "control_qubit": [], "target_qubit": [0],
      4             "control_value": [], "parameter": []})
      5 qc.add_gate({"name": "x", "control_qubit": [0], "target_qubit": [1],
      6             "control_value": [1], "parameter": []})
----> 7 assert_not_entangled(circuit=qc)

File /mnt/workspace/quantestpy_fork/quantestpy/assertion/not_entangled.py:79, in assert_not_entangled(circuit, qubits, atol, msg)
     77 err_msg = "\n".join(err_msg_list)
     78 msg = ut_test_case._formatMessage(msg, err_msg)
---> 79 raise QuantestPyAssertionError(msg)

QuantestPyAssertionError: qubit 0 is entangled with qubit(s) [1].
qubit 1 is entangled with qubit(s) [0].

In [4]: 
In [4]: # check specific qubits, not entangled
   ...: qc = QuantestPyCircuit(4)
   ...: qc.add_gate({"name": "h", "control_qubit": [], "target_qubit": [0],
   ...:             "control_value": [], "parameter": []})
   ...: qc.add_gate({"name": "x", "control_qubit": [0], "target_qubit": [1],
   ...:             "control_value": [1], "parameter": []})
   ...: assert_not_entangled(circuit=qc, qubits=[2, 3])

In [5]: 
In [5]: # check specific qubits, entangled
   ...: qc = QuantestPyCircuit(4)
   ...: qc.add_gate({"name": "h", "control_qubit": [], "target_qubit": [0],
   ...:             "control_value": [], "parameter": []})
   ...: qc.add_gate({"name": "x", "control_qubit": [0], "target_qubit": [1],
   ...:             "control_value": [1], "parameter": []})
   ...: qc.add_gate({"name": "x", "control_qubit": [1], "target_qubit": [2],
   ...:              "control_value": [1], "parameter": []})
   ...: assert_not_entangled(circuit=qc, qubits=[2, 3])
---------------------------------------------------------------------------
QuantestPyAssertionError                  Traceback (most recent call last)
Cell In [5], line 9
      5 qc.add_gate({"name": "x", "control_qubit": [0], "target_qubit": [1],
      6             "control_value": [1], "parameter": []})
      7 qc.add_gate({"name": "x", "control_qubit": [1], "target_qubit": [2],
      8              "control_value": [1], "parameter": []})
----> 9 assert_not_entangled(circuit=qc, qubits=[2, 3])

File /mnt/workspace/quantestpy_fork/quantestpy/assertion/not_entangled.py:79, in assert_not_entangled(circuit, qubits, atol, msg)
     77 err_msg = "\n".join(err_msg_list)
     78 msg = ut_test_case._formatMessage(msg, err_msg)
---> 79 raise QuantestPyAssertionError(msg)

QuantestPyAssertionError: qubit 2 is entangled with qubit(s) [0, 1].

In [6]: 

@junnaka51 junnaka51 linked an issue Jan 17, 2023 that may be closed by this pull request
@junnaka51 junnaka51 requested a review from mitz1012 January 18, 2023 01:19
@mitz1012
Copy link
Contributor

I tried to merge the previous pull request in GitHub, but the merging is blocked. Could you merge it?

@junnaka51
Copy link
Contributor Author

@mitz1012

I tried to merge the previous pull request in GitHub, but the merging is blocked. Could you merge it?

The merging is blocked since this PR is not approved yet. Could you please approve first if there is no problem or comment, then we can merge this PR?

@mitz1012
Copy link
Contributor

@mitz1012

I tried to merge the previous pull request in GitHub, but the merging is blocked. Could you merge it?

The merging is blocked since this PR is not approved yet. Could you please approve first if there is no problem or comment, then we can merge this PR?

sorry for my misunderstanding...

Copy link
Contributor

@mitz1012 mitz1012 left a comment

Choose a reason for hiding this comment

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

There can be other entanglement states in the case len(val_pair_uniq_list) == 3. Could you change the part "Search for entangled pairs".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an assert method checking entanglement
2 participants