예제 #1
0
 def standard_table(self, fmt):
     # Render
     table = ReportTable(self.customHeadings,
                         ['Normal'] * 4)  # Four formats
     table.addrow(['1.0'], ['Normal'])
     table.render(fmt)
     table.finish()
예제 #2
0
 def setUp(self):
     super(PrecisionFormatterBase, self).setUp()
     n = 1.819743  # Six digits after decimal
     self.table = ReportTable([n], ['Normal'])
     self.options = dict(precision=self.precision, polarprecision=3)
     format_n = "{{:.{}f}}".format(self.precision).format(n)
     self.expected_LaTeX = self.expected_LaTeX_fmt.format(format_n)
     self.expected_HTML = self.expected_HTML_fmt.format(n, format_n)
예제 #3
0
    def test_general(self):

        table = ReportTable(['1.0'], ['Normal'])
        table.addrow(['1.0'], ['Normal'])
        table.render('text')

        self.assertTrue(table.has_key('1.0'))

        rowLabels = list(table.keys())
        row1Data = table[rowLabels[0]]
        colLabels = list(row1Data.keys())

        self.assertTrue(rowLabels, table.row_names)
        self.assertTrue(colLabels, table.col_names)
        self.assertTrue(len(rowLabels), table.num_rows)
        self.assertTrue(len(colLabels), table.num_cols)

        el00 = table[rowLabels[0]][colLabels[0]]
        self.assertTrue(rowLabels[0] in table)
        self.assertTrue(rowLabels[0] in table)

        table_len = len(table)
        self.assertEqual(table_len, table.num_rows)

        table_as_str = str(table)
        row1a = table.row(key=rowLabels[0])
        col1a = table.col(key=colLabels[0])
        row1b = table.row(index=0)
        col1b = table.col(index=0)
        self.assertEqual(row1a, row1b)
        self.assertEqual(col1a, col1b)

        with self.assertRaises(KeyError):
            table['foobar']
        with self.assertRaises(KeyError):
            table.row(key='foobar')  #invalid key
        with self.assertRaises(ValueError):
            table.row(index=100000)  #out of bounds
        with self.assertRaises(ValueError):
            table.row()  #must specify key or index
        with self.assertRaises(ValueError):
            table.row(key='foobar', index=1)  #cannot specify key and index
        with self.assertRaises(KeyError):
            table.col(key='foobar')  #invalid key
        with self.assertRaises(ValueError):
            table.col(index=100000)  #out of bounds
        with self.assertRaises(ValueError):
            table.col()  #must specify key or index
        with self.assertRaises(ValueError):
            table.col(key='foobar', index=1)  #cannot specify key and index

        with self.assertRaises(ValueError):
            table.render(fmt="foobar")  #invalid format
예제 #4
0
    def setUp(self):
        super(FigureFormatterTest, self).setUp()

        self.figLatex = '\\begin{tabular}[l]{|c|}\n\hline\n\\vcenteredhbox{\includegraphics[width=100.00in,height=100.00in,keepaspectratio]{temp_test_files/test_figure.pdf}} \\\\ \hline\n\end{tabular}\n'

        stateSpace = [
            2
        ]  # Hilbert space has dimension 2; density matrix is a 2x2 matrix
        spaceLabels = [
            ('Q0', )
        ]  #interpret the 2x2 density matrix as a single qubit named 'Q0'
        gx = pc.build_gate(stateSpace, spaceLabels, "X(pi/2,Q0)")
        reportFig = pplt.gate_matrix_boxplot(gx,
                                             mxBasis="pp",
                                             mxBasisDims=2,
                                             xlabel="testX",
                                             ylabel="testY",
                                             title="mytitle",
                                             boxLabels=True)
        figInfo = (reportFig, 'test_figure', 100, 100)  # Fig, Name, Size, Size
        headings = [figInfo]
        formatters = ['Figure']
        self.table = ReportTable(headings, formatters)
예제 #5
0
def render_pair(heading, formatter, formattype='latex', **kwargs):
    # TODO render directly instead of through ReportTable
    table = ReportTable([heading], [formatter])
    return table.render(formattype, **kwargs)[formattype]
예제 #6
0
 def render_pair(self, heading, formatter, formattype='latex', **kwargs):
     headings = [heading]
     formatters = [formatter]
     table = ReportTable(headings, formatters)
     return table.render(formattype, **kwargs)[formattype]
예제 #7
0
 def custom_headings_no_format(self, fmt):
     table = ReportTable(self.customHeadings, None)
     table.render(fmt)
예제 #8
0
 def custom_headings(self, fmt):
     table = ReportTable(self.headings, self.formatters,
                         self.customHeadings)
     table.render(fmt)
예제 #9
0
 def setUp(self):
     self.table = ReportTable(self.custom_headings, None)
예제 #10
0
 def setUp(self):
     self.table = ReportTable([0.1], ['Normal'], self.custom_headings)
예제 #11
0
 def setUp(self):
     self.table = ReportTable(self.custom_headings,
                              ['Normal'] * 4)  # Four formats