Repository: qutip/qutip

Issue:
More detailed information for GSoC 2020 project
I have some detail information for the GSoC 2020  project "Error mitigation in QuTiP". Unfortunately, I don't have writing access to the QuTiP GitHub Wiki page. I post it here so if anyone finding it nice could copy it to the Wiki page.

I add some details based on the original description:

-----------------------------------
## 1. Error mitigation in QuTiP
From the QuTiP 4.5 release, the qutip.qip module now contains the noisy quantum circuit simulator (which was a GSoC project) providing enhanced features for a pulse-level description of quantum circuits and noise models. A new class `Processor` and several subclasses are added to represent different platforms for quantum computing. They can transfer a quantum circuit into the corresponding control sequence and simulate the dynamics with QuTiP solvers. Different noise models can be added to `qutip.qip.noise` to simulate noise in a quantum device. 

This module is still young and many features can be improved, including new device models, new noise models and integration with the existing general framework for quantum circuits (`qutip.qip.circuit`). There are also possible applications such as error mitigation techniques [1-3].

The tutorial notebooks can be found at http://qutip.org/tutorials.html#nisq. A recent presentation on the FOSDEM conference may help you get an overview (https://fosdem.org/2020/schedule/event/quantum_qutip/). See also the Github Project page for a collection of related issues and ongoing Pull Requests.

### Expected outcomes
 - More devices defined in the `qutip.qip.device` module. At the moment, we have two models: spin chain and cavity QED. We would like to include some other commonly used planform such as Superconducting system, Ion trap system or silicon system. Each model will need a new set of control hamiltonian and a compiler that find the control pulse of a quantum gate. This part is gonna involve some physics and study of commonly used hardware platforms. The related code can be found in `qutip.qip.device` and `qutip.qip.compiler`
- Refactoring the circuit compiler to allow simple pulse scheduling, e.g. Restriction one pulses that can be turned on at the same time.
- Features to perform error mitigation techniques in QuTiP, such as zero-error extrapolation.
- APIs to allow import quantum circuits from other software packages or commonly used language e.g. through quantum assembly language (qasm)
----------------------------------------------------------------

Also, the last outcomes have some overlap with the last project. Although I also find this circuit importation very important, I guess two projects should not have overlap if they are both selected.


Discussion:
Hi Boxi,

Can you please modify the projects of the Wiki page as you deem best?
All: we can also think of changing the order of them. It may be that
project #3 is deemed the most important.

Best wishes,

Nathan

Dr. Nathan Shammah
Postdoctoral Research Scientist
Theoretical Quantum Physics Laboratory
RIKEN, Wako, Saitama, Japan
www.nathanshammah.com



On Sun, Feb 23, 2020 at 5:42 AM Boxi Li <notifications@github.com> wrote:

> I have some detail information for the GSoC 2020 project "Error mitigation
> in QuTiP". Unfortunately, I don't have writing access to the QuTiP GitHub
> Wiki page. I post it here so if anyone finds it nice could copy it to the
> Wiki page.
>
> I add some details based on the original description:
> ------------------------------
> 1. Error mitigation in QuTiP
>
> From the QuTiP 4.5 release, the qutip.qip module now contains the noisy
> quantum circuit simulator (which was a GSoC project) providing enhanced
> features for a pulse-level description of quantum circuits and noise
> models. A new class Processor and several subclasses are added to
> represent different platforms for quantum computing. They can transfer a
> quantum circuit into the corresponding control sequence and simulate the
> dynamics with QuTiP solvers. Different noise models can be added to
> qutip.qip.noise to simulate noise in a quantum device.
>
> This module is still young and many features can be improved, including
> new device models, new noise models and integration with the existing
> general framework for quantum circuits (qutip.qip.circuit). There are
> also possible applications such as error mitigation techniques [1-3].
>
> The tutorial notebooks can be found at
> http://qutip.org/tutorials.html#nisq. A recent presentation on the FOSDEM
> conference may help you get an overview (
> https://fosdem.org/2020/schedule/event/quantum_qutip/). See also the
> Github Project page for a collection of related issues and ongoing Pull
> Requests.
> Expected outcomes
>
>    - More devices defined in the qutip.qip.device module. At the moment,
>    we have two models: spin chain and cavity QED. We would like to include
>    some other commonly used planform such as Superconducting system, Ion trap
>    system or silicon system. Each model will need a new set of control
>    hamiltonian and a compiler that find the control pulse of a quantum gate.
>    This part is gonna involve some physics and study of commonly used hardware
>    platforms. The related code can be found in qutip.qip.device and
>    qutip.qip.compiler
>    - Refactoring the circuit compiler to allow simple pulse scheduling,
>    e.g. Restriction one pulses that can be turned on at the same time.
>    - Features to perform error mitigation techniques in QuTiP, such as
>    zero-error extrapolation.
>    - APIs to allow import quantum circuits from other software packages
>    or commonly used language e.g. through quantum assembly language (qasm)
>
> ------------------------------
>
> Also, the last outcomes have some overlap with the last project. Although
> I also find this circuit importation very important, I guess two projects
> should not have overlap if they are both selected.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/qutip/qutip/issues/1184?email_source=notifications&email_token=ADPF67A5MSYZVSDKCZD73LTREGE2LA5CNFSM4KZUPCQ2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IPQGYLA>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ADPF67EWECDUIOQMTKK2N2DREGE2LANCNFSM4KZUPCQQ>
> .
>

Hi Nathan,

I can't modify the Wiki page because I'm not a maintainer of QuTiP. And it seems that there is no way to make a PR to Wiki. I can also send you the markdown source code per email like this, but I’m not sure if it works as I expected.

The following is the markdown source code:

-----------------------------------
## 1. Error mitigation in QuTiP
From the QuTiP 4.5 release, the qutip.qip module now contains the noisy quantum circuit simulator (which was a GSoC project) providing enhanced features for a pulse-level description of quantum circuits and noise models. A new class `Processor` and several subclasses are added to represent different platforms for quantum computing. They can transfer a quantum circuit into the corresponding control sequence and simulate the dynamics with QuTiP solvers. Different noise models can be added to `qutip.qip.noise` to simulate noise in a quantum device.

This module is still young and many features can be improved, including new device models, new noise models and integration with the existing general framework for quantum circuits (`qutip.qip.circuit`). There are also possible applications such as error mitigation techniques [1-3].

The tutorial notebooks can be found at http://qutip.org/tutorials.html#nisq. A recent presentation on the FOSDEM conference may help you get an overview (https://fosdem.org/2020/schedule/event/quantum_qutip/). See also the Github Project page for a collection of related issues and ongoing Pull Requests.

### Expected outcomes
- More devices defined in the `qutip.qip.device` module. At the moment, we have two models: spin chain and cavity QED. We would like to include some other commonly used planform such as Superconducting system, Ion trap system or silicon system. Each model will need a new set of control hamiltonian and a compiler that find the control pulse of a quantum gate. This part is gonna involve some physics and study of commonly used hardware platforms. The related code can be found in `qutip.qip.device` and `qutip.qip.compiler`
- Refactoring the circuit compiler to allow simple pulse scheduling, e.g. Restriction one pulses that can be turned on at the same time.
- Features to perform error mitigation techniques in QuTiP, such as zero-error extrapolation.
- APIs to allow import quantum circuits from other software packages or commonly used language e.g. through quantum assembly language (qasm)
----------------------------------------------------------------

Best
Boxi
Hi,

Yes, I know, that's why I added the md file. I updated it now, thanks,
adding more info on general resources to learn about QuTiP and more
references to the #3 project, i.e. your blog and the talk.
https://github.com/qutip/qutip/wiki/Google-Summer-of-Code-2020

Neill, Alex, if you have a lead, please add a HEOM project.

Bests,

Nathan

Dr. Nathan Shammah
Postdoctoral Research Scientist
Theoretical Quantum Physics Laboratory
RIKEN, Wako, Saitama, Japan
www.nathanshammah.com


On Tue, Feb 25, 2020 at 5:10 PM Boxi Li <notifications@github.com> wrote:

> Hi Nathan,
>
> I can't modify the Wiki page because I'm not a maintainer of QuTiP. And it
> seems that there is no way to make a PR to Wiki. I can also send you the
> markdown source code per email like this, but I’m not sure if it works as I
> expected.
>
> The following is the markdown source code:
>
> -----------------------------------
> ## 1. Error mitigation in QuTiP
> From the QuTiP 4.5 release, the qutip.qip module now contains the noisy
> quantum circuit simulator (which was a GSoC project) providing enhanced
> features for a pulse-level description of quantum circuits and noise
> models. A new class `Processor` and several subclasses are added to
> represent different platforms for quantum computing. They can transfer a
> quantum circuit into the corresponding control sequence and simulate the
> dynamics with QuTiP solvers. Different noise models can be added to
> `qutip.qip.noise` to simulate noise in a quantum device.
>
> This module is still young and many features can be improved, including
> new device models, new noise models and integration with the existing
> general framework for quantum circuits (`qutip.qip.circuit`). There are
> also possible applications such as error mitigation techniques [1-3].
>
> The tutorial notebooks can be found at
> http://qutip.org/tutorials.html#nisq. A recent presentation on the FOSDEM
> conference may help you get an overview (
> https://fosdem.org/2020/schedule/event/quantum_qutip/). See also the
> Github Project page for a collection of related issues and ongoing Pull
> Requests.
>
> ### Expected outcomes
> - More devices defined in the `qutip.qip.device` module. At the moment, we
> have two models: spin chain and cavity QED. We would like to include some
> other commonly used planform such as Superconducting system, Ion trap
> system or silicon system. Each model will need a new set of control
> hamiltonian and a compiler that find the control pulse of a quantum gate.
> This part is gonna involve some physics and study of commonly used hardware
> platforms. The related code can be found in `qutip.qip.device` and
> `qutip.qip.compiler`
> - Refactoring the circuit compiler to allow simple pulse scheduling, e.g.
> Restriction one pulses that can be turned on at the same time.
> - Features to perform error mitigation techniques in QuTiP, such as
> zero-error extrapolation.
> - APIs to allow import quantum circuits from other software packages or
> commonly used language e.g. through quantum assembly language (qasm)
> ----------------------------------------------------------------
>
> Best
> Boxi
>
> From: Nathan Shammah<mailto:notifications@github.com>
> Sent: Tuesday, February 25, 2020 8:36 AM
> To: qutip/qutip<mailto:qutip@noreply.github.com>
> Cc: Boxi Li<mailto:etamin1201@gmail.com>; Author<mailto:
> author@noreply.github.com>
> Subject: Re: [qutip/qutip] More detailed information for GSoC 2020 project
> (#1184)
>
> Hi Boxi,
>
> Can you please modify the projects of the Wiki page as you deem best?
> All: we can also think of changing the order of them. It may be that
> project #3 is deemed the most important.
>
> Best wishes,
>
> Nathan
>
> Dr. Nathan Shammah
> Postdoctoral Research Scientist
> Theoretical Quantum Physics Laboratory
> RIKEN, Wako, Saitama, Japan
> www.nathanshammah.com
>
>
>
> On Sun, Feb 23, 2020 at 5:42 AM Boxi Li <notifications@github.com> wrote:
>
> > I have some detail information for the GSoC 2020 project "Error
> mitigation
> > in QuTiP". Unfortunately, I don't have writing access to the QuTiP GitHub
> > Wiki page. I post it here so if anyone finds it nice could copy it to the
> > Wiki page.
> >
> > I add some details based on the original description:
> > ------------------------------
> > 1. Error mitigation in QuTiP
> >
> > From the QuTiP 4.5 release, the qutip.qip module now contains the noisy
> > quantum circuit simulator (which was a GSoC project) providing enhanced
> > features for a pulse-level description of quantum circuits and noise
> > models. A new class Processor and several subclasses are added to
> > represent different platforms for quantum computing. They can transfer a
> > quantum circuit into the corresponding control sequence and simulate the
> > dynamics with QuTiP solvers. Different noise models can be added to
> > qutip.qip.noise to simulate noise in a quantum device.
> >
> > This module is still young and many features can be improved, including
> > new device models, new noise models and integration with the existing
> > general framework for quantum circuits (qutip.qip.circuit). There are
> > also possible applications such as error mitigation techniques [1-3].
> >
> > The tutorial notebooks can be found at
> > http://qutip.org/tutorials.html#nisq. A recent presentation on the
> FOSDEM
> > conference may help you get an overview (
> > https://fosdem.org/2020/schedule/event/quantum_qutip/). See also the
> > Github Project page for a collection of related issues and ongoing Pull
> > Requests.
> > Expected outcomes
> >
> > - More devices defined in the qutip.qip.device module. At the moment,
> > we have two models: spin chain and cavity QED. We would like to include
> > some other commonly used planform such as Superconducting system, Ion
> trap
> > system or silicon system. Each model will need a new set of control
> > hamiltonian and a compiler that find the control pulse of a quantum gate.
> > This part is gonna involve some physics and study of commonly used
> hardware
> > platforms. The related code can be found in qutip.qip.device and
> > qutip.qip.compiler
> > - Refactoring the circuit compiler to allow simple pulse scheduling,
> > e.g. Restriction one pulses that can be turned on at the same time.
> > - Features to perform error mitigation techniques in QuTiP, such as
> > zero-error extrapolation.
> > - APIs to allow import quantum circuits from other software packages
> > or commonly used language e.g. through quantum assembly language (qasm)
> >
> > ------------------------------
> >
> > Also, the last outcomes have some overlap with the last project. Although
> > I also find this circuit importation very important, I guess two projects
> > should not have overlap if they are both selected.
> >
> > —
> > You are receiving this because you are subscribed to this thread.
> > Reply to this email directly, view it on GitHub
> > <
> https://github.com/qutip/qutip/issues/1184?email_source=notifications&email_token=ADPF67A5MSYZVSDKCZD73LTREGE2LA5CNFSM4KZUPCQ2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IPQGYLA
> >,
> > or unsubscribe
> > <
> https://github.com/notifications/unsubscribe-auth/ADPF67EWECDUIOQMTKK2N2DREGE2LANCNFSM4KZUPCQQ
> >
> > .
> >
>
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub<
> https://github.com/qutip/qutip/issues/1184?email_source=notifications&email_token=AC4QMV2SERZDZGO2EGF677DRETDBTA5CNFSM4KZUPCQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEM24JKI#issuecomment-590726313>,
> or unsubscribe<
> https://github.com/notifications/unsubscribe-auth/AC4QMV6SNJVGD5YZKSBN7WDRETDBTANCNFSM4KZUPCQQ
> >.
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/qutip/qutip/issues/1184?email_source=notifications&email_token=ADPF67HHX4IG7LOZAF3XLK3RETG6BA5CNFSM4KZUPCQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEM27EFA#issuecomment-590737940>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ADPF67DIYOYUO35BGQNKCEDRETG6BANCNFSM4KZUPCQQ>
> .
>

updated on the Wiki GSoC 2020 page. https://github.com/qutip/qutip/wiki/Google-Summer-of-Code-2020

Resolving patch:
diff --git a/qutip/fileio.py b/qutip/fileio.py
--- a/qutip/fileio.py
+++ b/qutip/fileio.py
@@ -3,8 +3,7 @@
 import pickle
 import numpy as np
 import sys
-from qutip.qobj import Qobj
-from qutip.solver import Result
+from pathlib import Path
 
 
 # -----------------------------------------------------------------------------
@@ -16,7 +15,7 @@ def file_data_store(filename, data, numtype="complex", numformat="decimal",
 
     Parameters
     ----------
-    filename : str
+    filename : str or pathlib.Path
         Name of data file to be stored, including extension.
     data: array_like
         Data to be written to file.
@@ -112,7 +111,7 @@ def file_data_read(filename, sep=None):
 
     Parameters
     ----------
-    filename : str
+    filename : str or pathlib.Path
         Name of file containing reqested data.
     sep : str
         Seperator used to store data.
@@ -217,15 +216,17 @@ def qsave(data, name='qutip_data'):
     ----------
     data : instance/array_like
         Input Python object to be stored.
-    filename : str
+    filename : str or pathlib.Path
         Name of output data file.
 
     """
     # open the file for writing
-    fileObject = open(name + '.qu', 'wb')
-    # this writes the object a to the file named 'filename.qu'
-    pickle.dump(data, fileObject)
-    fileObject.close()
+    file = Path(name)
+    file = file.with_suffix(file.suffix + ".qu")
+
+    with open(name, "wb") as fileObject:
+        # this writes the object a to the file named 'filename.qu'
+        pickle.dump(data, fileObject)
 
 
 def qload(name):
@@ -234,7 +235,7 @@ def qload(name):
 
     Parameters
     ----------
-    name : str
+    name : str or pathlib.Path
         Name of data file to be loaded.
 
     Returns
@@ -243,23 +244,13 @@ def qload(name):
         Object retrieved from requested file.
 
     """
-    with open(name + ".qu", "rb") as fileObject:
+    file = Path(name)
+    file = file.with_suffix(file.suffix + ".qu")
+
+    with open(name, "rb") as fileObject:
         if sys.version_info >= (3, 0):
             out = pickle.load(fileObject, encoding='latin1')
         else:
             out = pickle.load(fileObject)
-    if isinstance(out, Qobj):  # for quantum objects
-        print('Loaded Qobj object:')
-        str1 = "Quantum object: " + "dims = " + str(out.dims) \
-            + ", shape = " + str(out.shape) + ", type = " + out.type
-        if out.type == 'oper' or out.type == 'super':
-            str1 += ", isHerm = " + str(out.isherm) + "\n"
-        else:
-            str1 += "\n"
-        print(str1)
-    elif isinstance(out, Result):
-        print('Loaded Result object:')
-        print(out)
-    else:
-        print("Loaded " + str(type(out).__name__) + " object.")
+
     return out


Test patch:
diff --git a/qutip/tests/test_fileio.py b/qutip/tests/test_fileio.py
--- a/qutip/tests/test_fileio.py
+++ b/qutip/tests/test_fileio.py
@@ -2,6 +2,7 @@
 import numpy as np
 import uuid
 import qutip
+from pathlib import Path
 
 # qsave _always_ appends a suffix to the file name at the time of writing, but
 # in case this changes in the future, to ensure that we never leak a temporary
@@ -44,11 +45,15 @@ def test_separator_detection(self, separator):
         return self.case(_random_file_name(), kwargs)
 
 
-def test_qsave_qload():
+@pytest.mark.parametrize('use_path', [True, False], ids=['Path', 'str'])
+@pytest.mark.parametrize('suffix', ['', '.qu', '.dat'])
+def test_qsave_qload(use_path, suffix):
     ops_in = [qutip.sigmax(),
               qutip.num(_dimension),
               qutip.coherent_dm(_dimension, 1j)]
-    filename = _random_file_name()
+    filename = _random_file_name() + suffix
+    if use_path:
+        filename = Path.cwd() / filename
     qutip.qsave(ops_in, filename)
     ops_out = qutip.qload(filename)
     assert ops_in == ops_out